diff --git a/go.mod b/go.mod index 2b5dd36..9de5756 100644 --- a/go.mod +++ b/go.mod @@ -3,21 +3,19 @@ module github.com/metal-stack/cli go 1.26 require ( - buf.build/go/protoyaml v0.6.0 connectrpc.com/connect v1.19.1 connectrpc.com/validate v0.6.0 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.18.0 github.com/google/go-cmp v0.7.0 github.com/metal-stack/api v0.0.58 - github.com/metal-stack/metal-lib v0.24.0 + github.com/metal-stack/metal-lib v0.24.2-0.20260324151418-0917620d251f github.com/metal-stack/v v1.0.3 github.com/spf13/afero v1.15.0 github.com/spf13/cobra v1.10.2 - github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 - google.golang.org/grpc v1.79.1 + google.golang.org/grpc v1.79.3 google.golang.org/protobuf v1.36.11 sigs.k8s.io/yaml v1.6.0 ) @@ -25,6 +23,7 @@ require ( require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20260209202127-80ab13bee0bf.1 // indirect buf.build/go/protovalidate v1.1.3 // indirect + buf.build/go/protoyaml v0.6.0 // indirect cel.dev/expr v0.25.1 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -59,6 +58,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.12.0 // indirect github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect github.com/stretchr/objx v0.5.3 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.mongodb.org/mongo-driver v1.17.9 // indirect diff --git a/go.sum b/go.sum index d420c4c..5f7458d 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,8 @@ github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjc github.com/mattn/go-runewidth v0.0.20/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= github.com/metal-stack/api v0.0.58 h1:7UxnZrM41BS0f4S9RvqDg0/YTvs3FveawuyBoKz9WhA= github.com/metal-stack/api v0.0.58/go.mod h1:hEgtKVD7UnUwUExdA7pbFvVRxNRxSGUnU+bZce46//c= -github.com/metal-stack/metal-lib v0.24.0 h1:wvQQPWIXcA2tP+I6zAHUNdtVLLJfQnnV9yG2SoqUkz4= -github.com/metal-stack/metal-lib v0.24.0/go.mod h1:oITaqj/BtB9vDKM66jCXkeA+4D0eTZElgIKal5vtiNY= +github.com/metal-stack/metal-lib v0.24.2-0.20260324151418-0917620d251f h1:qTEfCIrCsE8YTSIhMiI2jYlDqO20K3S4pCNkB9wB3vQ= +github.com/metal-stack/metal-lib v0.24.2-0.20260324151418-0917620d251f/go.mod h1:u1wQl98JOfzyXqY7+0qD2xFSMnxvzCykkLgW80U1IrA= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg= github.com/minio/minlz v1.1.0 h1:rUOGu3EP4EqJC5k3qCsIwEnZiJULKqtRyDdqbhlvMmQ= @@ -137,8 +137,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20260316180232-0b37fe3546d5 h1: google.golang.org/genproto/googleapis/api v0.0.0-20260316180232-0b37fe3546d5/go.mod h1:EIQZ5bFCfRQDV4MhRle7+OgjNtZ6P1PiZBgAKuxXu/Y= google.golang.org/genproto/googleapis/rpc v0.0.0-20260316180232-0b37fe3546d5 h1:aJmi6DVGGIStN9Mobk/tZOOQUBbj0BPjZjjnOdoZKts= google.golang.org/genproto/googleapis/rpc v0.0.0-20260316180232-0b37fe3546d5/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY= -google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= +google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE= +google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/testing/e2e/test_cmd.go b/testing/e2e/test_cmd.go index 93504f4..c8a24ca 100644 --- a/testing/e2e/test_cmd.go +++ b/testing/e2e/test_cmd.go @@ -1,4 +1,4 @@ -package e2e +package e2erootcmd import ( "bytes" @@ -12,6 +12,7 @@ import ( "github.com/metal-stack/cli/cmd" "github.com/metal-stack/cli/cmd/completion" "github.com/metal-stack/cli/cmd/config" + e2e_test "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/stretchr/testify/require" @@ -23,7 +24,7 @@ type TestConfig struct { ClientCalls []client.ClientCall } -func NewRootCmd(t *testing.T, c *TestConfig) NewRootCmdFunc { +func NewRootCmd(t *testing.T, c *TestConfig) e2e_test.NewRootCmdFunc { return func() (*cobra.Command, *bytes.Buffer) { interceptors := []connect.Interceptor{ client.NewTestInterceptor(t, c.ClientCalls), diff --git a/testing/e2e/test_framework.go b/testing/e2e/test_framework.go deleted file mode 100644 index af794df..0000000 --- a/testing/e2e/test_framework.go +++ /dev/null @@ -1,373 +0,0 @@ -package e2e - -import ( - "bytes" - "encoding/json" - "fmt" - "os" - "strings" - "testing" - "testing/synctest" - "time" - - "slices" - - "buf.build/go/protoyaml" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/metal-stack/metal-lib/pkg/pointer" - "github.com/metal-stack/metal-lib/pkg/testcommon" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/runtime/protoimpl" - "google.golang.org/protobuf/testing/protocmp" - "sigs.k8s.io/yaml" -) - -const ( - InputFilePath = "/file.yaml" -) - -// NewRootCmdFunc returns the root command for the cli and an output buffer which returns the output after command execution -type NewRootCmdFunc func() (rootCmd *cobra.Command, out *bytes.Buffer) - -type Test[Response, RawObject any] struct { - Name string - - NewRootCmd NewRootCmdFunc - CmdArgs []string - Out *bytes.Buffer - - AssertExhaustiveArgs bool - AssertExhaustiveExcludes []string - - // output format tests - WantObject RawObject // for rawyaml / rawjson printer - WantProtoObject proto.Message // for yaml / json printer - WantTable *string // for table printer - WantWideTable *string // for wide table printer - WantMarkdown *string // for markdown printer - WantTemplate *string // for template printer - Template *string // for template printer - - WantErr error -} - -func TimeBubbleStartTime() time.Time { - return time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) -} - -func (c *Test[Response, RawObject]) TestCmd(t *testing.T) { - require.NotEmpty(t, c.Name, "test name must not be empty") - require.NotEmpty(t, c.CmdArgs, "cmd must not be empty") - - if c.AssertExhaustiveArgs { - c.assertExhaustiveArgs(t) - } - - if c.WantErr != nil { - rootCmd, _ := c.NewRootCmd() - - os.Args = append([]string{rootCmd.Use}, c.CmdArgs...) - - synctest.Test(t, func(t *testing.T) { - err := rootCmd.Execute() - if diff := cmp.Diff(c.WantErr, err, testcommon.IgnoreUnexported(), testcommon.ErrorStringComparer()); diff != "" { - t.Errorf("error diff (+got -want):\n %s", diff) - } - }) - } - - formats := outputFormats(c) - - if len(formats) == 0 { - t.Errorf("at least one want section for output formats must be specified, otherwise no command is getting executed") - return - } - - for _, format := range formats { - succeeded := t.Run(fmt.Sprintf("%v", format.Args()), func(t *testing.T) { - rootCmd, out := c.NewRootCmd() - - os.Args = append([]string{rootCmd.Use}, c.CmdArgs...) - os.Args = append(os.Args, format.Args()...) - - synctest.Test(t, func(t *testing.T) { - err := rootCmd.Execute() - require.NoError(t, err) - }) - - format.Validate(t, out.Bytes()) - }) - - if !succeeded { - t.FailNow() - } - } -} - -func (c *Test[Response, RawObject]) assertExhaustiveArgs(t *testing.T) { - assertContainsPrefix := func(ss []string, prefix string) error { - for _, s := range ss { - if strings.HasPrefix(s, prefix) { - return nil - } - } - return fmt.Errorf("not exhaustive: does not contain %q", prefix) - } - - rootCmd, _ := c.NewRootCmd() - - cmd, args, err := rootCmd.Find(c.CmdArgs) - require.NoError(t, err) - - cmd.LocalFlags().VisitAll(func(f *pflag.Flag) { - if slices.Contains(c.AssertExhaustiveExcludes, f.Name) { - return - } - - require.NoError(t, assertContainsPrefix(args, "--"+f.Name), "ensure all available args are used in order to increase coverage") - }) -} - -func outputFormats[Response, RawObject any](c *Test[Response, RawObject]) []outputFormat { - var formats []outputFormat - - if !pointer.IsZero(c.WantObject) { - formats = append(formats, - &rawYamlOutputFormat[RawObject]{want: c.WantObject}, - &rawJsonOutputFormat[RawObject]{want: c.WantObject}, - ) - } - - if c.WantProtoObject != nil { - formats = append(formats, - &protoYAMLOutputFormat[Response]{want: c.WantProtoObject}, - &protoJSONOutputFormat[Response]{want: c.WantProtoObject}, - ) - } - - if c.WantTable != nil { - formats = append(formats, &tableOutputFormat{table: *c.WantTable}) - } - - if c.WantWideTable != nil { - formats = append(formats, &wideTableOutputFormat{table: *c.WantWideTable}) - } - - if c.Template != nil && c.WantTemplate != nil { - formats = append(formats, &templateOutputFormat{template: *c.Template, templateOutput: *c.WantTemplate}) - } - - if c.WantMarkdown != nil { - formats = append(formats, &markdownOutputFormat{table: *c.WantMarkdown}) - } - - return formats -} - -type outputFormat interface { - Args() []string - Validate(t *testing.T, output []byte) -} - -type rawYamlOutputFormat[R any] struct { - want R -} - -func (o *rawYamlOutputFormat[R]) Args() []string { - return []string{"-o", "yamlraw"} -} - -func (o *rawYamlOutputFormat[R]) Validate(t *testing.T, output []byte) { - t.Logf("got following yamlraw output:\n\n%s\n", string(output)) - - var got R - - err := yaml.Unmarshal(output, &got) - require.NoError(t, err) - - if diff := cmp.Diff(o.want, got, testcommon.IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { - t.Errorf("diff (+got -want):\n %s", diff) - } -} - -type rawJsonOutputFormat[R any] struct { - want R -} - -func (o *rawJsonOutputFormat[R]) Args() []string { - return []string{"-o", "jsonraw"} -} - -func (o *rawJsonOutputFormat[R]) Validate(t *testing.T, output []byte) { - t.Logf("got following jsonraw output:\n\n%s\n", string(output)) - - var got R - - err := json.Unmarshal(output, &got) - require.NoError(t, err) - - if diff := cmp.Diff(o.want, got, testcommon.IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { - t.Errorf("diff (+got -want):\n %s", diff) - } -} - -type protoYAMLOutputFormat[R any] struct { - want proto.Message -} - -func (o *protoYAMLOutputFormat[R]) Args() []string { - return []string{"-o", "yaml"} -} - -func (o *protoYAMLOutputFormat[R]) Validate(t *testing.T, output []byte) { - t.Logf("got following yaml output:\n\n%s\n", string(output)) - - got := proto.Clone(o.want) - proto.Reset(got) - - err := protoyaml.Unmarshal(output, got) - require.NoError(t, err) - - if diff := cmp.Diff(o.want, got, protocmp.Transform(), testcommon.IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { - t.Errorf("diff (+got -want):\n %s", diff) - } -} - -type protoJSONOutputFormat[R any] struct { - want proto.Message -} - -func (o *protoJSONOutputFormat[R]) Args() []string { - return []string{"-o", "json"} -} - -func (o *protoJSONOutputFormat[R]) Validate(t *testing.T, output []byte) { - t.Logf("got following json output:\n\n%s\n", string(output)) - - got := proto.Clone(o.want) - proto.Reset(got) - - err := protojson.Unmarshal(output, got) - require.NoError(t, err) - - if diff := cmp.Diff(o.want, got, protocmp.Transform(), testcommon.IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { - t.Errorf("diff (+got -want):\n %s", diff) - } -} - -type tableOutputFormat struct { - table string -} - -func (o *tableOutputFormat) Args() []string { - return []string{"-o", "table"} -} - -func (o *tableOutputFormat) Validate(t *testing.T, output []byte) { - validateTableRows(t, o.table, string(output)) -} - -type wideTableOutputFormat struct { - table string -} - -func (o *wideTableOutputFormat) Args() []string { - return []string{"-o", "wide"} -} - -func (o *wideTableOutputFormat) Validate(t *testing.T, output []byte) { - validateTableRows(t, o.table, string(output)) -} - -type templateOutputFormat struct { - template string - templateOutput string -} - -func (o *templateOutputFormat) Args() []string { - return []string{"-o", "template", "--template", o.template} -} - -func (o *templateOutputFormat) Validate(t *testing.T, output []byte) { - t.Logf("got following template output:\n\n%s\n\nconsider using this for test comparison if it looks correct.", string(output)) - - if diff := cmp.Diff(strings.TrimSpace(o.templateOutput), strings.TrimSpace(string(output))); diff != "" { - t.Errorf("diff (+got -want):\n %s", diff) - } -} - -type markdownOutputFormat struct { - table string -} - -func (o *markdownOutputFormat) Args() []string { - return []string{"-o", "markdown"} -} - -func (o *markdownOutputFormat) Validate(t *testing.T, output []byte) { - validateTableRows(t, o.table, string(output)) -} - -func validateTableRows(t *testing.T, want, got string) { - trimAll := func(ss []string) []string { - var res []string - for _, s := range ss { - res = append(res, strings.TrimSpace(s)) - } - return res - } - - var ( - trimmedWant = strings.TrimSpace(want) - trimmedGot = strings.TrimSpace(string(got)) - - wantRows = trimAll(strings.Split(trimmedWant, "\n")) - gotRows = trimAll(strings.Split(trimmedGot, "\n")) - ) - - t.Logf("got following table output:\n\n%s\n\nconsider using this for test comparison if it looks correct.", trimmedGot) - - // somehow this diff does not look nice anymore. :( - // t.Log(cmp.Diff(trimmedWant, trimmedGot)) - - require.Equal(t, len(wantRows), len(gotRows), "tables have different lengths") - - for i := range wantRows { - wantFields := trimAll(strings.Split(wantRows[i], " ")) - gotFields := trimAll(strings.Split(gotRows[i], " ")) - - require.Equal(t, len(wantFields), len(gotFields), "table fields have different lengths") - - for i := range wantFields { - assert.Equal(t, wantFields[i], gotFields[i]) - } - } -} - -func CommonExcludedFileArgs() []string { - return []string{"file", "bulk-output", "skip-security-prompts", "timestamps"} -} - -func AppendFromFileCommonArgs(args ...string) []string { - return append(args, []string{"-f", InputFilePath, "--skip-security-prompts", "--bulk-output"}...) -} - -func MustMarshal(t *testing.T, d any) []byte { - b, err := json.MarshalIndent(d, "", " ") - require.NoError(t, err) - return b -} - -func MustMarshalToMultiYAML(t *testing.T, data ...any) []byte { - var parts []string - for _, elem := range data { - parts = append(parts, string(MustMarshal(t, elem))) - } - return []byte(strings.Join(parts, "\n---\n")) -} diff --git a/tests/e2e/admin/component_test.go b/tests/e2e/admin/component_test.go index cd9c43b..ebf66b8 100644 --- a/tests/e2e/admin/component_test.go +++ b/tests/e2e/admin/component_test.go @@ -8,7 +8,8 @@ import ( "github.com/metal-stack/api/go/client" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -55,7 +56,7 @@ func Test_AdminComponentCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"admin", "component", "describe", component1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.ComponentServiceGetRequest{ @@ -100,7 +101,7 @@ func Test_AdminComponentCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"admin", "component", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.ComponentServiceListRequest{ @@ -150,7 +151,7 @@ func Test_AdminComponentCmd_Delete(t *testing.T) { { Name: "delete", CmdArgs: []string{"admin", "component", "delete", component1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.ComponentServiceDeleteRequest{ diff --git a/tests/e2e/admin/project_test.go b/tests/e2e/admin/project_test.go index 357e227..423a49c 100644 --- a/tests/e2e/admin/project_test.go +++ b/tests/e2e/admin/project_test.go @@ -7,8 +7,9 @@ import ( "github.com/metal-stack/api/go/client" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) func Test_AdminProjectCmd_List(t *testing.T) { @@ -16,7 +17,7 @@ func Test_AdminProjectCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"admin", "project", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.ProjectServiceListRequest{}, diff --git a/tests/e2e/admin/switch_test.go b/tests/e2e/admin/switch_test.go index 1cd9985..3a7086a 100644 --- a/tests/e2e/admin/switch_test.go +++ b/tests/e2e/admin/switch_test.go @@ -8,7 +8,8 @@ import ( "github.com/metal-stack/api/go/client" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -65,7 +66,7 @@ func Test_AdminSwitchCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"admin", "switch", "describe", switch1().Id}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.SwitchServiceGetRequest{ @@ -93,7 +94,7 @@ func Test_AdminSwitchCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"admin", "switch", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.SwitchServiceListRequest{ @@ -145,7 +146,7 @@ func Test_AdminSwitchCmd_Delete(t *testing.T) { { Name: "delete", CmdArgs: []string{"admin", "switch", "delete", switch1().Id}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.SwitchServiceDeleteRequest{ diff --git a/tests/e2e/admin/tenant_test.go b/tests/e2e/admin/tenant_test.go index 3914611..5b8cf43 100644 --- a/tests/e2e/admin/tenant_test.go +++ b/tests/e2e/admin/tenant_test.go @@ -7,7 +7,8 @@ import ( "github.com/metal-stack/api/go/client" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -41,7 +42,7 @@ func Test_AdminTenantCmd_Create(t *testing.T) { { Name: "create", CmdArgs: []string{"admin", "tenant", "create", "--name", adminTenant1().Name, "--description", adminTenant1().Description, "--email", adminTenant1().Email}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.TenantServiceCreateRequest{ @@ -71,7 +72,7 @@ func Test_AdminTenantCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"admin", "tenant", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.TenantServiceListRequest{}, diff --git a/tests/e2e/admin/token_test.go b/tests/e2e/admin/token_test.go index 13b079b..136a50b 100644 --- a/tests/e2e/admin/token_test.go +++ b/tests/e2e/admin/token_test.go @@ -7,8 +7,9 @@ import ( "github.com/metal-stack/api/go/client" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) func Test_AdminTokenCmd_List(t *testing.T) { @@ -16,7 +17,7 @@ func Test_AdminTokenCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"admin", "token", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.TokenServiceListRequest{}, @@ -64,7 +65,7 @@ func Test_AdminTokenCmd_Delete(t *testing.T) { { Name: "delete", CmdArgs: []string{"admin", "token", "delete", testresources.Token1().Uuid, "--user", "user-123"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &adminv2.TokenServiceRevokeRequest{ diff --git a/tests/e2e/api/audit_test.go b/tests/e2e/api/audit_test.go index dfe062e..dc7afd5 100644 --- a/tests/e2e/api/audit_test.go +++ b/tests/e2e/api/audit_test.go @@ -6,8 +6,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/grpc/codes" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -48,7 +49,7 @@ func Test_AuditCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"audit", "list", "--tenant", "a"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.AuditServiceListRequest{ @@ -100,7 +101,7 @@ func Test_AuditCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"audit", "describe", "--tenant", "a", Trace1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.AuditServiceGetRequest{ diff --git a/tests/e2e/api/health_test.go b/tests/e2e/api/health_test.go index 1562a1e..08f845e 100644 --- a/tests/e2e/api/health_test.go +++ b/tests/e2e/api/health_test.go @@ -6,7 +6,8 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) var ( @@ -28,7 +29,7 @@ func Test_HealthCmd(t *testing.T) { { Name: "health", CmdArgs: []string{"health"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.HealthServiceGetRequest{}, diff --git a/tests/e2e/api/image_test.go b/tests/e2e/api/image_test.go index 2419326..14c13af 100644 --- a/tests/e2e/api/image_test.go +++ b/tests/e2e/api/image_test.go @@ -6,8 +6,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) func Test_ImageCmd_List(t *testing.T) { @@ -15,7 +16,7 @@ func Test_ImageCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"image", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ImageServiceListRequest{ @@ -66,7 +67,7 @@ func Test_ImageCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"image", "describe", testresources.Image1().Id}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ImageServiceGetRequest{ diff --git a/tests/e2e/api/ip_test.go b/tests/e2e/api/ip_test.go index d7fa668..45053f2 100644 --- a/tests/e2e/api/ip_test.go +++ b/tests/e2e/api/ip_test.go @@ -7,8 +7,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -18,7 +19,7 @@ func Test_IPCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"ip", "list", "--project", testresources.IP1().Project}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.IPServiceListRequest{ @@ -68,7 +69,7 @@ func Test_IPCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"ip", "describe", "--project", testresources.IP1().Project, testresources.IP1().Ip}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.IPServiceGetRequest{ @@ -114,7 +115,7 @@ func Test_IPCmd_Create(t *testing.T) { { Name: "create", CmdArgs: []string{"ip", "create", "--project", testresources.IP1().Project, "--network", testresources.IP1().Network, "--static=true"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.IPServiceCreateRequest{ @@ -135,8 +136,8 @@ func Test_IPCmd_Create(t *testing.T) { { Name: "create from file", CmdArgs: append([]string{"ip", "create"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.IP1()), 0755)) }, @@ -187,7 +188,7 @@ func Test_IPCmd_Delete(t *testing.T) { { Name: "delete", CmdArgs: []string{"ip", "delete", "--project", testresources.IP1().Project, testresources.IP1().Ip}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.IPServiceDeleteRequest{ @@ -207,8 +208,8 @@ func Test_IPCmd_Delete(t *testing.T) { { Name: "delete from file", CmdArgs: append([]string{"ip", "delete"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.IP1()), 0755)) }, @@ -254,8 +255,8 @@ func Test_IPCmd_Update(t *testing.T) { { Name: "update", CmdArgs: []string{"ip", "update", "--project", testresources.IP1().Project, testresources.IP1().Ip, "--name", "foo"}, - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ // TODO: the client gets the IP two times? { @@ -307,8 +308,8 @@ func Test_IPCmd_Update(t *testing.T) { { Name: "update from file", CmdArgs: append([]string{"ip", "update"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.IP1()), 0755)) }, @@ -360,8 +361,8 @@ func Test_IPCmd_Apply(t *testing.T) { { Name: "apply", CmdArgs: append([]string{"ip", "apply"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.IP1()), 0755)) }, @@ -405,8 +406,8 @@ func Test_IPCmd_Apply(t *testing.T) { { Name: "apply already exists", CmdArgs: append([]string{"ip", "apply"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, - &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.IP1()), 0755)) }, diff --git a/tests/e2e/api/project_test.go b/tests/e2e/api/project_test.go index 2d748ea..343bf1b 100644 --- a/tests/e2e/api/project_test.go +++ b/tests/e2e/api/project_test.go @@ -6,8 +6,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func Test_ProjectCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"project", "describe", testresources.Project1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ProjectServiceGetRequest{ @@ -62,7 +63,7 @@ func Test_ProjectCmd_Create(t *testing.T) { { Name: "create", CmdArgs: []string{"project", "create", "--name", testresources.Project1().Name, "--description", testresources.Project1().Description, "--tenant", testresources.Project1().Tenant}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ProjectServiceCreateRequest{ @@ -84,7 +85,7 @@ func Test_ProjectCmd_Create(t *testing.T) { { Name: "create from file", CmdArgs: append([]string{"project", "create"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.Project1()), 0755)) }, @@ -111,7 +112,7 @@ func Test_ProjectCmd_Create(t *testing.T) { { Name: "create many from file", CmdArgs: append([]string{"project", "create"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshalToMultiYAML(t, testresources.Project1(), testresources.Project2()), 0755)) }, @@ -159,7 +160,7 @@ func Test_ProjectCmd_Delete(t *testing.T) { { Name: "delete", CmdArgs: []string{"project", "delete", testresources.Project1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ProjectServiceDeleteRequest{ @@ -178,7 +179,7 @@ func Test_ProjectCmd_Delete(t *testing.T) { { Name: "delete from file", CmdArgs: append([]string{"project", "delete"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.Project1()), 0755)) }, @@ -211,7 +212,7 @@ func Test_ProjectCmd_Update(t *testing.T) { { Name: "update", CmdArgs: []string{"project", "update", testresources.Project1().Uuid, "--name", "new-name", "--description", "new-desc"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ProjectServiceUpdateRequest{ @@ -232,7 +233,7 @@ func Test_ProjectCmd_Update(t *testing.T) { { Name: "update from file", CmdArgs: append([]string{"project", "update"}, e2e.AppendFromFileCommonArgs()...), - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ FsMocks: func(fs *afero.Afero) { require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.Project1()), 0755)) }, @@ -267,7 +268,7 @@ func Test_ProjectCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"project", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.ProjectServiceListRequest{}, diff --git a/tests/e2e/api/tenant_test.go b/tests/e2e/api/tenant_test.go index 3936dc2..7935e9b 100644 --- a/tests/e2e/api/tenant_test.go +++ b/tests/e2e/api/tenant_test.go @@ -6,8 +6,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) func Test_TenantCmd_Describe(t *testing.T) { @@ -15,7 +16,7 @@ func Test_TenantCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"tenant", "describe", testresources.Tenant1().Login}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.TenantServiceGetRequest{ @@ -60,7 +61,7 @@ func Test_TenantCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"tenant", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.TenantServiceListRequest{}, diff --git a/tests/e2e/api/token_test.go b/tests/e2e/api/token_test.go index d02766e..77ad210 100644 --- a/tests/e2e/api/token_test.go +++ b/tests/e2e/api/token_test.go @@ -6,8 +6,9 @@ import ( "connectrpc.com/connect" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" "github.com/metal-stack/cli/tests/e2e/testresources" + "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" ) func Test_TokenCmd_Describe(t *testing.T) { @@ -15,7 +16,7 @@ func Test_TokenCmd_Describe(t *testing.T) { { Name: "describe", CmdArgs: []string{"token", "describe", testresources.Token1().Uuid}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.TokenServiceGetRequest{ @@ -60,7 +61,7 @@ func Test_TokenCmd_List(t *testing.T) { { Name: "list", CmdArgs: []string{"token", "list"}, - NewRootCmd: e2e.NewRootCmd(t, &e2e.TestConfig{ + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ ClientCalls: []client.ClientCall{ { WantRequest: &apiv2.TokenServiceListRequest{}, diff --git a/tests/e2e/testresources/projects.go b/tests/e2e/testresources/projects.go index 3f06a38..c1c107e 100644 --- a/tests/e2e/testresources/projects.go +++ b/tests/e2e/testresources/projects.go @@ -2,7 +2,7 @@ package testresources import ( apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/tests/e2e/testresources/tenants.go b/tests/e2e/testresources/tenants.go index 05b958b..9226681 100644 --- a/tests/e2e/testresources/tenants.go +++ b/tests/e2e/testresources/tenants.go @@ -2,7 +2,7 @@ package testresources import ( apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/tests/e2e/testresources/tokens.go b/tests/e2e/testresources/tokens.go index b3349d6..fcfa890 100644 --- a/tests/e2e/testresources/tokens.go +++ b/tests/e2e/testresources/tokens.go @@ -4,7 +4,7 @@ import ( "time" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "github.com/metal-stack/cli/testing/e2e" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" "google.golang.org/protobuf/types/known/timestamppb" )