From 34925054f4a51f4d04905fc8d57bd1b4bf13750e Mon Sep 17 00:00:00 2001 From: pauhull Date: Tue, 2 Jan 2024 13:57:07 +0100 Subject: [PATCH 1/5] feat: add global --quiet flag to hide progress indicators Closes #644 --- internal/cli/root.go | 9 +++++++++ internal/cmd/base/create.go | 6 +++--- internal/state/helpers.go | 8 ++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/cli/root.go b/internal/cli/root.go index e467322b..aca8171b 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -63,6 +63,7 @@ func NewRootCommand(s state.State) *cobra.Command { primaryip.NewCommand(s), ) cmd.PersistentFlags().Duration("poll-interval", 500*time.Millisecond, "Interval at which to poll information, for example action progress") + cmd.PersistentFlags().Bool("quiet", false, "Only print error messages") cmd.SetOut(os.Stdout) cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { pollInterval, err := cmd.Flags().GetDuration("poll-interval") @@ -70,6 +71,14 @@ func NewRootCommand(s state.State) *cobra.Command { return err } s.Client().WithOpts(hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval))) + + if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { + f, err := os.Open(os.DevNull) + if err != nil { + return err + } + cmd.SetOut(f) + } return nil } return cmd diff --git a/internal/cmd/base/create.go b/internal/cmd/base/create.go index 496a0dd0..cbd4460e 100644 --- a/internal/cmd/base/create.go +++ b/internal/cmd/base/create.go @@ -42,11 +42,11 @@ func (cc *CreateCmd) CobraCommand(s state.State) *cobra.Command { cmd.RunE = func(cmd *cobra.Command, args []string) error { outputFlags := output.FlagsForCommand(cmd) + quiet, _ := cmd.Flags().GetBool("quiet") + isSchema := outputFlags.IsSet("json") || outputFlags.IsSet("yaml") - if isSchema { + if isSchema && !quiet { cmd.SetOut(os.Stderr) - } else { - cmd.SetOut(os.Stdout) } resource, schema, err := cc.Run(s, cmd, args) diff --git a/internal/state/helpers.go b/internal/state/helpers.go index 25a00c19..b3f8f7cf 100644 --- a/internal/state/helpers.go +++ b/internal/state/helpers.go @@ -36,6 +36,10 @@ func (c *state) ActionProgress(cmd *cobra.Command, ctx context.Context, action * func (c *state) ActionsProgresses(cmd *cobra.Command, ctx context.Context, actions []*hcloud.Action) error { progressCh, errCh := c.Client().Action().WatchOverallProgress(ctx, actions) + if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { + return <-errCh + } + if StdoutIsTerminal() { progress := pb.New(100) progress.SetMaxWidth(50) // width of progress bar is too large by default @@ -101,6 +105,10 @@ func DisplayProgressCircle(cmd *cobra.Command, errCh <-chan error, waitingFor st ellipsis = " ... " ) + if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { + return <-errCh + } + if StdoutIsTerminal() { _, _ = fmt.Fprintln(os.Stderr, waitingFor) From d77f2545a99f8102ad8d0eb790c8b0b7504442b7 Mon Sep 17 00:00:00 2001 From: pauhull <22707808+pauhull@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:48:15 +0100 Subject: [PATCH 2/5] test: add tests for --quiet flag --- internal/cmd/base/create_test.go | 155 ++++++++++++++++++++ internal/cmd/base/delete_test.go | 80 ++++++++++ internal/cmd/base/describe.go | 8 + internal/cmd/base/describe_test.go | 159 ++++++++++++++++++++ internal/cmd/base/list_test.go | 228 +++++++++++++++++++++++++++++ 5 files changed, 630 insertions(+) create mode 100644 internal/cmd/base/create_test.go create mode 100644 internal/cmd/base/delete_test.go create mode 100644 internal/cmd/base/describe_test.go create mode 100644 internal/cmd/base/list_test.go diff --git a/internal/cmd/base/create_test.go b/internal/cmd/base/create_test.go new file mode 100644 index 00000000..797f11f4 --- /dev/null +++ b/internal/cmd/base/create_test.go @@ -0,0 +1,155 @@ +package base_test + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/cmd/util" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/cli/internal/state" + "github.com/hetznercloud/cli/internal/testutil" +) + +type fakeResource struct { + ID int `json:"id"` + Name string `json:"name"` +} + +var commandCalled bool + +var fakeCreateCmd = base.CreateCmd{ + BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { + return &cobra.Command{ + Use: "create", + } + }, + Run: func(s state.State, cmd *cobra.Command, strings []string) (any, any, error) { + cmd.Println("Creating fake resource") + commandCalled = true + + resource := &fakeResource{ + ID: 123, + Name: "test", + } + + return resource, util.Wrap("resource", resource), nil + }, +} + +func TestCreate(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Equal(t, "Creating fake resource\n", out) + assert.Empty(t, errOut) +} + +func TestCreateJSON(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create", "-o=json"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Equal(t, "Creating fake resource\n", errOut) +} + +func TestCreateYAML(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create", "-o=yaml"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Equal(t, "Creating fake resource\n", errOut) +} + +func TestCreateQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Empty(t, out) + assert.Empty(t, errOut) +} + +func TestCreateJSONQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create", "-o=json", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Empty(t, errOut) +} + +func TestCreateYAMLQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"create", "-o=yaml", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Empty(t, errOut) +} diff --git a/internal/cmd/base/delete_test.go b/internal/cmd/base/delete_test.go new file mode 100644 index 00000000..80ca8ecb --- /dev/null +++ b/internal/cmd/base/delete_test.go @@ -0,0 +1,80 @@ +package base_test + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/cli/internal/state" + "github.com/hetznercloud/cli/internal/testutil" + "github.com/hetznercloud/hcloud-go/v2/hcloud" +) + +var fakeDeleteCmd = base.DeleteCmd{ + ResourceNameSingular: "Fake resource", + Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { + cmd.Println("Deleting fake resource") + commandCalled = true + return nil + }, + + Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { + cmd.Println("Fetching fake resource") + + resource := &fakeResource{ + ID: 123, + Name: "test", + } + + return resource, nil, nil + }, + + NameSuggestions: func(client hcapi2.Client) func() []string { + return nil + }, +} + +func TestDelete(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDeleteCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"delete", "123"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Equal(t, `Fetching fake resource +Deleting fake resource +Fake resource 123 deleted +`, out) + assert.Empty(t, errOut) +} + +func TestDeleteQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDeleteCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"delete", "123", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Empty(t, out) + assert.Empty(t, errOut) +} diff --git a/internal/cmd/base/describe.go b/internal/cmd/base/describe.go index 5d50faf1..2edb556d 100644 --- a/internal/cmd/base/describe.go +++ b/internal/cmd/base/describe.go @@ -2,6 +2,7 @@ package base import ( "fmt" + "os" "reflect" "strings" @@ -54,6 +55,13 @@ func (dc *DescribeCmd) CobraCommand(s state.State) *cobra.Command { func (dc *DescribeCmd) Run(s state.State, cmd *cobra.Command, args []string) error { outputFlags := output.FlagsForCommand(cmd) + quiet, _ := cmd.Flags().GetBool("quiet") + + isSchema := outputFlags.IsSet("json") || outputFlags.IsSet("yaml") + if isSchema && !quiet { + cmd.SetOut(os.Stderr) + } + idOrName := args[0] resource, schema, err := dc.Fetch(s, cmd, idOrName) if err != nil { diff --git a/internal/cmd/base/describe_test.go b/internal/cmd/base/describe_test.go new file mode 100644 index 00000000..755bce5f --- /dev/null +++ b/internal/cmd/base/describe_test.go @@ -0,0 +1,159 @@ +package base_test + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/cmd/util" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/cli/internal/state" + "github.com/hetznercloud/cli/internal/testutil" +) + +var fakeDescribeCmd = base.DescribeCmd{ + ResourceNameSingular: "Fake resource", + + Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { + cmd.Println("Fetching fake resource") + commandCalled = true + + resource := &fakeResource{ + ID: 123, + Name: "test", + } + + return resource, util.Wrap("resource", resource), nil + }, + + PrintText: func(s state.State, cmd *cobra.Command, resource interface{}) error { + rsc := resource.(*fakeResource) + cmd.Printf("ID: %d\n", rsc.ID) + cmd.Printf("Name: %s\n", rsc.Name) + return nil + }, + + NameSuggestions: func(client hcapi2.Client) func() []string { + return nil + }, +} + +func TestDescribe(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Equal(t, `Fetching fake resource +ID: 123 +Name: test +`, out) + assert.Empty(t, errOut) +} + +func TestDescribeJSON(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=json"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Equal(t, "Fetching fake resource\n", errOut) +} + +func TestDescribeYAML(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=yaml"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Equal(t, "Fetching fake resource\n", errOut) +} + +func TestDescribeQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Empty(t, out) + assert.Empty(t, errOut) +} + +func TestDescribeJSONQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=json", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Empty(t, errOut) +} + +func TestDescribeYAMLQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=yaml", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) + assert.Empty(t, errOut) +} diff --git a/internal/cmd/base/list_test.go b/internal/cmd/base/list_test.go new file mode 100644 index 00000000..d5b9321a --- /dev/null +++ b/internal/cmd/base/list_test.go @@ -0,0 +1,228 @@ +package base_test + +import ( + "fmt" + "testing" + + "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/cmd/output" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/cli/internal/state" + "github.com/hetznercloud/cli/internal/testutil" + "github.com/hetznercloud/hcloud-go/v2/hcloud" +) + +var fakeListCmd = base.ListCmd{ + ResourceNamePlural: "Fake resources", + + Schema: func(i []interface{}) interface{} { + return i + }, + + OutputTable: func(client hcapi2.Client) *output.Table { + return output.NewTable(). + AddAllowedFields(hcloud.Firewall{}). + AddFieldFn("id", func(obj interface{}) string { + rsc := obj.(*fakeResource) + return fmt.Sprintf("%d", rsc.ID) + }). + AddFieldFn("name", func(obj interface{}) string { + rsc := obj.(*fakeResource) + return rsc.Name + }) + }, + + DefaultColumns: []string{"id", "name"}, + + Fetch: func(s state.State, set *pflag.FlagSet, opts hcloud.ListOpts, strings []string) ([]interface{}, error) { + commandCalled = true + return []interface{}{ + &fakeResource{ + ID: 123, + Name: "test", + }, + &fakeResource{ + ID: 321, + Name: "test2", + }, + &fakeResource{ + ID: 42, + Name: "test3", + }, + }, nil + }, +} + +func TestList(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Equal(t, "ID NAME\n123 test\n321 test2\n42 test3\n", out) + assert.Empty(t, errOut) +} + +func TestListJSON(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list", "-o=json"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, ` +[ + { + "id": 123, + "name": "test" + }, + { + "id": 321, + "name": "test2" + }, + { + "id": 42, + "name": "test3" + } +]`, out) + assert.Empty(t, errOut) +} + +func TestListYAML(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list", "-o=json"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, ` +[ + { + "id": 123, + "name": "test" + }, + { + "id": 321, + "name": "test2" + }, + { + "id": 42, + "name": "test3" + } +]`, out) + assert.Empty(t, errOut) +} + +func TestListQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.Equal(t, "ID NAME\n123 test\n321 test2\n42 test3\n", out) + assert.Empty(t, errOut) +} + +func TestListJSONQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list", "-o=json", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.JSONEq(t, ` +[ + { + "id": 123, + "name": "test" + }, + { + "id": 321, + "name": "test2" + }, + { + "id": 42, + "name": "test3" + } +]`, out) + assert.Empty(t, errOut) +} + +func TestListYAMLQuiet(t *testing.T) { + commandCalled = false + + fx := testutil.NewFixture(t) + defer fx.Finish() + + cmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(cmd, []string{"list", "-o=json", "--quiet"}) + + assert.Equal(t, true, commandCalled) + assert.NoError(t, err) + assert.YAMLEq(t, ` +[ + { + "id": 123, + "name": "test" + }, + { + "id": 321, + "name": "test2" + }, + { + "id": 42, + "name": "test3" + } +]`, out) + assert.Empty(t, errOut) +} From eb4da87e86705e5d4511dc3f06c4d153243461fa Mon Sep 17 00:00:00 2001 From: pauhull <22707808+pauhull@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:51:47 +0100 Subject: [PATCH 3/5] move logic --- internal/cli/root.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/cli/root.go b/internal/cli/root.go index aca8171b..0c2995a4 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -64,7 +64,7 @@ func NewRootCommand(s state.State) *cobra.Command { ) cmd.PersistentFlags().Duration("poll-interval", 500*time.Millisecond, "Interval at which to poll information, for example action progress") cmd.PersistentFlags().Bool("quiet", false, "Only print error messages") - cmd.SetOut(os.Stdout) + cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { pollInterval, err := cmd.Flags().GetDuration("poll-interval") if err != nil { @@ -72,13 +72,14 @@ func NewRootCommand(s state.State) *cobra.Command { } s.Client().WithOpts(hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval))) + out := os.Stdout if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { - f, err := os.Open(os.DevNull) + out, err = os.Open(os.DevNull) if err != nil { return err } - cmd.SetOut(f) } + cmd.SetOut(out) return nil } return cmd From 344fbf3e69de1a69dcb9fa276f7d3c4c3789f73f Mon Sep 17 00:00:00 2001 From: pauhull <22707808+pauhull@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:50:53 +0100 Subject: [PATCH 4/5] refactor tests --- internal/cmd/base/create_test.go | 150 +++++---------------- internal/cmd/base/delete_test.go | 52 ++------ internal/cmd/base/describe_test.go | 150 +++++---------------- internal/cmd/base/list_test.go | 203 +++++------------------------ internal/testutil/cmd.go | 75 +++++++++++ 5 files changed, 184 insertions(+), 446 deletions(-) create mode 100644 internal/testutil/cmd.go diff --git a/internal/cmd/base/create_test.go b/internal/cmd/base/create_test.go index 797f11f4..be9244a6 100644 --- a/internal/cmd/base/create_test.go +++ b/internal/cmd/base/create_test.go @@ -4,9 +4,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" - "github.com/hetznercloud/cli/internal/cli" "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" @@ -19,9 +17,7 @@ type fakeResource struct { Name string `json:"name"` } -var commandCalled bool - -var fakeCreateCmd = base.CreateCmd{ +var fakeCreateCmd = &base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ Use: "create", @@ -29,7 +25,6 @@ var fakeCreateCmd = base.CreateCmd{ }, Run: func(s state.State, cmd *cobra.Command, strings []string) (any, any, error) { cmd.Println("Creating fake resource") - commandCalled = true resource := &fakeResource{ ID: 123, @@ -41,115 +36,36 @@ var fakeCreateCmd = base.CreateCmd{ } func TestCreate(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Equal(t, "Creating fake resource\n", out) - assert.Empty(t, errOut) -} - -func TestCreateJSON(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create", "-o=json"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Equal(t, "Creating fake resource\n", errOut) -} - -func TestCreateYAML(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create", "-o=yaml"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Equal(t, "Creating fake resource\n", errOut) -} - -func TestCreateQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Empty(t, out) - assert.Empty(t, errOut) -} - -func TestCreateJSONQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create", "-o=json", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Empty(t, errOut) -} - -func TestCreateYAMLQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeCreateCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"create", "-o=yaml", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Empty(t, errOut) + const resourceSchema = `{"resource": {"id": 123, "name": "test"}}` + testutil.TestCommand(t, fakeCreateCmd, map[string]testutil.TestCase{ + "no flags": { + Args: []string{"create"}, + ExpOut: "Creating fake resource\n", + }, + "json": { + Args: []string{"create", "-o=json"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + ExpErrOut: "Creating fake resource\n", + }, + "yaml": { + Args: []string{"create", "-o=yaml"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + ExpErrOut: "Creating fake resource\n", + }, + "quiet": { + Args: []string{"create", "--quiet"}, + }, + "json quiet": { + Args: []string{"create", "-o=json", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + }, + "yaml quiet": { + Args: []string{"create", "-o=yaml", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + }, + }) } diff --git a/internal/cmd/base/delete_test.go b/internal/cmd/base/delete_test.go index 80ca8ecb..f72cf9b2 100644 --- a/internal/cmd/base/delete_test.go +++ b/internal/cmd/base/delete_test.go @@ -4,9 +4,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" - "github.com/hetznercloud/cli/internal/cli" "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/cli/internal/state" @@ -14,11 +12,10 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -var fakeDeleteCmd = base.DeleteCmd{ +var fakeDeleteCmd = &base.DeleteCmd{ ResourceNameSingular: "Fake resource", Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { cmd.Println("Deleting fake resource") - commandCalled = true return nil }, @@ -39,42 +36,13 @@ var fakeDeleteCmd = base.DeleteCmd{ } func TestDelete(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDeleteCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"delete", "123"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Equal(t, `Fetching fake resource -Deleting fake resource -Fake resource 123 deleted -`, out) - assert.Empty(t, errOut) -} - -func TestDeleteQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDeleteCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"delete", "123", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Empty(t, out) - assert.Empty(t, errOut) + testutil.TestCommand(t, fakeDeleteCmd, map[string]testutil.TestCase{ + "no flags": { + Args: []string{"delete", "123"}, + ExpOut: "Fetching fake resource\nDeleting fake resource\nFake resource 123 deleted\n", + }, + "quiet": { + Args: []string{"delete", "123", "--quiet"}, + }, + }) } diff --git a/internal/cmd/base/describe_test.go b/internal/cmd/base/describe_test.go index 755bce5f..08130e18 100644 --- a/internal/cmd/base/describe_test.go +++ b/internal/cmd/base/describe_test.go @@ -4,9 +4,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" - "github.com/hetznercloud/cli/internal/cli" "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" @@ -14,12 +12,11 @@ import ( "github.com/hetznercloud/cli/internal/testutil" ) -var fakeDescribeCmd = base.DescribeCmd{ +var fakeDescribeCmd = &base.DescribeCmd{ ResourceNameSingular: "Fake resource", Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { cmd.Println("Fetching fake resource") - commandCalled = true resource := &fakeResource{ ID: 123, @@ -42,118 +39,39 @@ var fakeDescribeCmd = base.DescribeCmd{ } func TestDescribe(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Equal(t, `Fetching fake resource + const resourceSchema = `{"resource": {"id": 123, "name": "test"}}` + testutil.TestCommand(t, fakeDescribeCmd, map[string]testutil.TestCase{ + "no flags": { + Args: []string{"describe", "123"}, + ExpOut: `Fetching fake resource ID: 123 Name: test -`, out) - assert.Empty(t, errOut) -} - -func TestDescribeJSON(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=json"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Equal(t, "Fetching fake resource\n", errOut) -} - -func TestDescribeYAML(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=yaml"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Equal(t, "Fetching fake resource\n", errOut) -} - -func TestDescribeQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Empty(t, out) - assert.Empty(t, errOut) -} - -func TestDescribeJSONQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=json", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Empty(t, errOut) -} - -func TestDescribeYAMLQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeDescribeCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"describe", "123", "-o=yaml", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, `{"resource": {"id": 123, "name": "test"}}`, out) - assert.Empty(t, errOut) +`, + }, + "json": { + Args: []string{"describe", "123", "-o=json"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + ExpErrOut: "Fetching fake resource\n", + }, + "yaml": { + Args: []string{"describe", "123", "-o=yaml"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + ExpErrOut: "Fetching fake resource\n", + }, + "quiet": { + Args: []string{"describe", "123", "--quiet"}, + }, + "json quiet": { + Args: []string{"describe", "123", "-o=json", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + }, + "yaml quiet": { + Args: []string{"describe", "123", "-o=yaml", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + }, + }) } diff --git a/internal/cmd/base/list_test.go b/internal/cmd/base/list_test.go index d5b9321a..8b51c7a0 100644 --- a/internal/cmd/base/list_test.go +++ b/internal/cmd/base/list_test.go @@ -5,9 +5,7 @@ import ( "testing" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/hetznercloud/cli/internal/cli" "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/output" "github.com/hetznercloud/cli/internal/hcapi2" @@ -16,7 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -var fakeListCmd = base.ListCmd{ +var fakeListCmd = &base.ListCmd{ ResourceNamePlural: "Fake resources", Schema: func(i []interface{}) interface{} { @@ -39,7 +37,6 @@ var fakeListCmd = base.ListCmd{ DefaultColumns: []string{"id", "name"}, Fetch: func(s state.State, set *pflag.FlagSet, opts hcloud.ListOpts, strings []string) ([]interface{}, error) { - commandCalled = true return []interface{}{ &fakeResource{ ID: 123, @@ -58,171 +55,35 @@ var fakeListCmd = base.ListCmd{ } func TestList(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Equal(t, "ID NAME\n123 test\n321 test2\n42 test3\n", out) - assert.Empty(t, errOut) -} - -func TestListJSON(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list", "-o=json"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, ` -[ - { - "id": 123, - "name": "test" - }, - { - "id": 321, - "name": "test2" - }, - { - "id": 42, - "name": "test3" - } -]`, out) - assert.Empty(t, errOut) -} - -func TestListYAML(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list", "-o=json"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, ` -[ - { - "id": 123, - "name": "test" - }, - { - "id": 321, - "name": "test2" - }, - { - "id": 42, - "name": "test3" - } -]`, out) - assert.Empty(t, errOut) -} - -func TestListQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.Equal(t, "ID NAME\n123 test\n321 test2\n42 test3\n", out) - assert.Empty(t, errOut) -} - -func TestListJSONQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list", "-o=json", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.JSONEq(t, ` -[ - { - "id": 123, - "name": "test" - }, - { - "id": 321, - "name": "test2" - }, - { - "id": 42, - "name": "test3" - } -]`, out) - assert.Empty(t, errOut) -} - -func TestListYAMLQuiet(t *testing.T) { - commandCalled = false - - fx := testutil.NewFixture(t) - defer fx.Finish() - - cmd := cli.NewRootCommand(fx.State()) - fx.ExpectEnsureToken() - - cmd.AddCommand(fakeListCmd.CobraCommand(fx.State())) - - out, errOut, err := fx.Run(cmd, []string{"list", "-o=json", "--quiet"}) - - assert.Equal(t, true, commandCalled) - assert.NoError(t, err) - assert.YAMLEq(t, ` -[ - { - "id": 123, - "name": "test" - }, - { - "id": 321, - "name": "test2" - }, - { - "id": 42, - "name": "test3" - } -]`, out) - assert.Empty(t, errOut) + const resourceSchema = `[{"id": 123, "name": "test"}, {"id": 321, "name": "test2"}, {"id": 42, "name": "test3"}]` + testutil.TestCommand(t, fakeListCmd, map[string]testutil.TestCase{ + "no flags": { + Args: []string{"list"}, + ExpOut: "ID NAME\n123 test\n321 test2\n42 test3\n", + }, + "json": { + Args: []string{"list", "-o=json"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + }, + "yaml": { + Args: []string{"list", "-o=yaml"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + }, + "quiet": { + Args: []string{"list", "--quiet"}, + ExpOut: "ID NAME\n123 test\n321 test2\n42 test3\n", + }, + "json quiet": { + Args: []string{"list", "-o=json", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeJSON, + }, + "yaml quiet": { + Args: []string{"list", "-o=yaml", "--quiet"}, + ExpOut: resourceSchema, + ExpOutType: testutil.DataTypeYAML, + }, + }) } diff --git a/internal/testutil/cmd.go b/internal/testutil/cmd.go new file mode 100644 index 00000000..b0745b21 --- /dev/null +++ b/internal/testutil/cmd.go @@ -0,0 +1,75 @@ +package testutil + +import ( + "encoding/json" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/state" +) + +type TestableCommand interface { + CobraCommand(state.State) *cobra.Command +} + +type TestCase struct { + Args []string + ExpOut string + ExpOutType DataType + ExpErrOut string + ExpErrOutType DataType +} + +type DataType string + +const ( + DataTypeText DataType = "text" + DataTypeJSON DataType = "json" + DataTypeYAML DataType = "yaml" +) + +func (dt DataType) test(t *testing.T, expected string, actual string, _ ...any) bool { + switch dt { + case DataTypeJSON: + return assert.JSONEq(t, expected, actual) + case DataTypeYAML: + if json.Valid([]byte(actual)) { + t.Error("expected YAML, but got valid JSON") + return false + } + return assert.YAMLEq(t, expected, actual) + default: + return assert.Equal(t, expected, actual) + } +} + +func TestCommand(t *testing.T, cmd TestableCommand, cases map[string]TestCase) { + for name, testCase := range cases { + + if testCase.ExpOutType == "" { + testCase.ExpOutType = DataTypeText + } + if testCase.ExpErrOutType == "" { + testCase.ExpErrOutType = DataTypeText + } + + t.Run(name, func(t *testing.T) { + fx := NewFixture(t) + defer fx.Finish() + + rootCmd := cli.NewRootCommand(fx.State()) + fx.ExpectEnsureToken() + + rootCmd.AddCommand(cmd.CobraCommand(fx.State())) + + out, errOut, err := fx.Run(rootCmd, testCase.Args) + + assert.NoError(t, err) + testCase.ExpOutType.test(t, testCase.ExpOut, out) + testCase.ExpErrOutType.test(t, testCase.ExpErrOut, errOut) + }) + } +} From 1ffa0dc995c331d357d4bd6259730b40baeb6a6a Mon Sep 17 00:00:00 2001 From: pauhull <22707808+pauhull@users.noreply.github.com> Date: Thu, 4 Jan 2024 18:21:24 +0100 Subject: [PATCH 5/5] refactor: solve cyclic imports --- internal/cmd/all/all.go | 2 +- internal/cmd/all/list.go | 2 +- internal/cmd/all/list_test.go | 7 ++- internal/cmd/certificate/create_test.go | 11 ++-- internal/cmd/certificate/delete_test.go | 5 +- internal/cmd/certificate/describe_test.go | 5 +- internal/cmd/certificate/labels_test.go | 7 ++- internal/cmd/certificate/list_test.go | 5 +- internal/cmd/certificate/update_test.go | 5 +- internal/cmd/datacenter/describe_test.go | 5 +- internal/cmd/datacenter/list_test.go | 5 +- internal/cmd/firewall/add_rule.go | 4 +- internal/cmd/firewall/add_rule_test.go | 11 ++-- .../cmd/firewall/apply_to_resource_test.go | 19 ++++--- internal/cmd/firewall/create_test.go | 7 ++- internal/cmd/firewall/delete_rule.go | 4 +- internal/cmd/firewall/delete_rule_test.go | 11 ++-- internal/cmd/firewall/delete_test.go | 11 ++-- internal/cmd/firewall/describe_test.go | 11 ++-- internal/cmd/firewall/labels_test.go | 7 ++- internal/cmd/firewall/list_test.go | 5 +- .../cmd/firewall/remove_from_resource_test.go | 19 ++++--- internal/cmd/firewall/replace_rules_test.go | 11 ++-- internal/cmd/firewall/update_test.go | 5 +- internal/cmd/firewall/validation.go | 2 +- internal/cmd/firewall/validation_test.go | 6 +- internal/cmd/floatingip/assign_test.go | 5 +- internal/cmd/floatingip/create_test.go | 9 +-- internal/cmd/floatingip/delete_test.go | 5 +- internal/cmd/floatingip/describe_test.go | 5 +- .../cmd/floatingip/disable_protection_test.go | 5 +- .../cmd/floatingip/enable_protection_test.go | 5 +- internal/cmd/floatingip/labels_test.go | 7 ++- internal/cmd/floatingip/list_test.go | 5 +- internal/cmd/floatingip/set_rdns_test.go | 5 +- internal/cmd/floatingip/unassign_test.go | 5 +- internal/cmd/floatingip/update_test.go | 7 ++- internal/cmd/image/delete_test.go | 11 ++-- internal/cmd/image/describe_test.go | 5 +- internal/cmd/image/disable_protection_test.go | 5 +- internal/cmd/image/enable_protection_test.go | 5 +- internal/cmd/image/labels_test.go | 7 ++- internal/cmd/image/list_test.go | 5 +- internal/cmd/image/update_test.go | 7 ++- internal/cmd/iso/describe_test.go | 5 +- internal/cmd/iso/list_test.go | 5 +- internal/cmd/loadbalancer/add_service_test.go | 5 +- internal/cmd/loadbalancer/add_target_test.go | 9 +-- .../loadbalancer/attach_to_network_test.go | 5 +- .../cmd/loadbalancer/change_algorithm_test.go | 5 +- internal/cmd/loadbalancer/change_type_test.go | 5 +- internal/cmd/loadbalancer/create_test.go | 9 +-- .../cmd/loadbalancer/delete_service_test.go | 5 +- internal/cmd/loadbalancer/delete_test.go | 5 +- internal/cmd/loadbalancer/describe_test.go | 5 +- .../loadbalancer/detach_from_network_test.go | 5 +- .../loadbalancer/disable_protection_test.go | 5 +- .../disable_public_interface_test.go | 5 +- .../loadbalancer/enable_protection_test.go | 5 +- .../enable_public_interface_test.go | 5 +- internal/cmd/loadbalancer/labels_test.go | 7 ++- internal/cmd/loadbalancer/list.go | 4 +- internal/cmd/loadbalancer/list_test.go | 5 +- internal/cmd/loadbalancer/metrics_test.go | 5 +- .../cmd/loadbalancer/remove_target_test.go | 9 +-- internal/cmd/loadbalancer/set_rdns_test.go | 5 +- .../cmd/loadbalancer/update_service_test.go | 5 +- internal/cmd/loadbalancer/update_test.go | 5 +- .../cmd/loadbalancertype/describe_test.go | 5 +- internal/cmd/loadbalancertype/list_test.go | 5 +- internal/cmd/location/list_test.go | 5 +- internal/cmd/network/create_test.go | 15 ++--- internal/cmd/network/delete_test.go | 11 ++-- internal/cmd/network/describe_test.go | 11 ++-- internal/cmd/network/labels_test.go | 7 ++- internal/cmd/network/update_test.go | 5 +- internal/cmd/placementgroup/labels_test.go | 7 ++- internal/cmd/placementgroup/update_test.go | 5 +- internal/cmd/primaryip/assign_test.go | 5 +- internal/cmd/primaryip/changedns_test.go | 5 +- internal/cmd/primaryip/create_test.go | 7 ++- internal/cmd/primaryip/delete_test.go | 11 ++-- internal/cmd/primaryip/describe_test.go | 5 +- .../cmd/primaryip/disable_protection_test.go | 9 +-- .../cmd/primaryip/enable_protection_test.go | 9 +-- internal/cmd/primaryip/labels_test.go | 7 ++- internal/cmd/primaryip/list_test.go | 5 +- internal/cmd/primaryip/primaryip.go | 2 +- internal/cmd/primaryip/unassign_test.go | 5 +- internal/cmd/primaryip/update.go | 2 +- internal/cmd/primaryip/update_test.go | 7 ++- internal/cmd/server/delete_test.go | 5 +- internal/cmd/server/describe_test.go | 5 +- internal/cmd/server/labels_test.go | 7 ++- internal/cmd/server/list_test.go | 5 +- .../remove_from_placement_group_test.go | 10 ++-- internal/cmd/server/shutdown_test.go | 55 +++++++++---------- internal/cmd/server/update_test.go | 5 +- internal/cmd/servertype/describe_test.go | 5 +- internal/cmd/servertype/list_test.go | 5 +- internal/cmd/sshkey/create_test.go | 7 ++- internal/cmd/sshkey/delete_test.go | 5 +- internal/cmd/sshkey/describe_test.go | 5 +- internal/cmd/sshkey/labels_test.go | 7 ++- internal/cmd/sshkey/list_test.go | 5 +- internal/cmd/sshkey/update_test.go | 5 +- internal/cmd/volume/create_test.go | 15 ++--- internal/cmd/volume/delete_test.go | 11 ++-- internal/cmd/volume/describe_test.go | 11 ++-- internal/cmd/volume/labels_test.go | 7 ++- internal/cmd/volume/list_test.go | 5 +- internal/cmd/volume/update_test.go | 5 +- 112 files changed, 439 insertions(+), 339 deletions(-) diff --git a/internal/cmd/all/all.go b/internal/cmd/all/all.go index 83dc1743..08e11b91 100644 --- a/internal/cmd/all/all.go +++ b/internal/cmd/all/all.go @@ -15,7 +15,7 @@ func NewCommand(s state.State) *cobra.Command { DisableFlagsInUseLine: true, } cmd.AddCommand( - listCmd.CobraCommand(s), + ListCmd.CobraCommand(s), ) return cmd } diff --git a/internal/cmd/all/list.go b/internal/cmd/all/list.go index 1ec1a5df..37a9ac12 100644 --- a/internal/cmd/all/list.go +++ b/internal/cmd/all/list.go @@ -41,7 +41,7 @@ var allCmds = []base.ListCmd{ sshkey.ListCmd, } -var listCmd = base.Cmd{ +var ListCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { var resources []string diff --git a/internal/cmd/all/list_test.go b/internal/cmd/all/list_test.go index a28453b2..f01eb4c0 100644 --- a/internal/cmd/all/list_test.go +++ b/internal/cmd/all/list_test.go @@ -1,4 +1,4 @@ -package all +package all_test import ( _ "embed" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/all" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -22,7 +23,7 @@ func TestListAll(t *testing.T) { time.Local = time.UTC - cmd := listCmd.CobraCommand(fx.State()) + cmd := all.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). @@ -246,7 +247,7 @@ func TestListAllPaidJSON(t *testing.T) { time.Local = time.UTC - cmd := listCmd.CobraCommand(fx.State()) + cmd := all.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). diff --git a/internal/cmd/certificate/create_test.go b/internal/cmd/certificate/create_test.go index b197e2c8..212d3aff 100644 --- a/internal/cmd/certificate/create_test.go +++ b/internal/cmd/certificate/create_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( _ "embed" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -22,7 +23,7 @@ func TestCreateManaged(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := certificate.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). @@ -55,7 +56,7 @@ func TestCreateManagedJSON(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := certificate.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). @@ -104,7 +105,7 @@ func TestCreateUploaded(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := certificate.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). @@ -132,7 +133,7 @@ func TestCreateUploadedJSON(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := certificate.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). diff --git a/internal/cmd/certificate/delete_test.go b/internal/cmd/certificate/delete_test.go index 7d66a6bf..4e3cd6ec 100644 --- a/internal/cmd/certificate/delete_test.go +++ b/internal/cmd/certificate/delete_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := certificate.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() cert := &hcloud.Certificate{ diff --git a/internal/cmd/certificate/describe_test.go b/internal/cmd/certificate/describe_test.go index 6e7b0bee..9015ee97 100644 --- a/internal/cmd/certificate/describe_test.go +++ b/internal/cmd/certificate/describe_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -20,7 +21,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := certificate.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() cert := &hcloud.Certificate{ diff --git a/internal/cmd/certificate/labels_test.go b/internal/cmd/certificate/labels_test.go index d50cf046..493d02a9 100644 --- a/internal/cmd/certificate/labels_test.go +++ b/internal/cmd/certificate/labels_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := certificate.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := certificate.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). diff --git a/internal/cmd/certificate/list_test.go b/internal/cmd/certificate/list_test.go index fb7fe2ed..f5cb5d93 100644 --- a/internal/cmd/certificate/list_test.go +++ b/internal/cmd/certificate/list_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := certificate.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). diff --git a/internal/cmd/certificate/update_test.go b/internal/cmd/certificate/update_test.go index 91a3928d..411dfc86 100644 --- a/internal/cmd/certificate/update_test.go +++ b/internal/cmd/certificate/update_test.go @@ -1,4 +1,4 @@ -package certificate +package certificate_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := certificate.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.CertificateClient.EXPECT(). diff --git a/internal/cmd/datacenter/describe_test.go b/internal/cmd/datacenter/describe_test.go index 47cc0dc5..6d76c4eb 100644 --- a/internal/cmd/datacenter/describe_test.go +++ b/internal/cmd/datacenter/describe_test.go @@ -1,4 +1,4 @@ -package datacenter +package datacenter_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/datacenter" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDescribe(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := datacenter.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.DatacenterClient.EXPECT(). diff --git a/internal/cmd/datacenter/list_test.go b/internal/cmd/datacenter/list_test.go index ca8d202d..aa422924 100644 --- a/internal/cmd/datacenter/list_test.go +++ b/internal/cmd/datacenter/list_test.go @@ -1,4 +1,4 @@ -package datacenter +package datacenter_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/datacenter" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := datacenter.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.DatacenterClient.EXPECT(). diff --git a/internal/cmd/firewall/add_rule.go b/internal/cmd/firewall/add_rule.go index 736dd0e9..9fb468a5 100644 --- a/internal/cmd/firewall/add_rule.go +++ b/internal/cmd/firewall/add_rule.go @@ -87,7 +87,7 @@ var AddRuleCmd = base.Cmd{ case hcloud.FirewallRuleDirectionOut: rule.DestinationIPs = make([]net.IPNet, len(destinationIPs)) for i, ip := range destinationIPs { - n, err := validateFirewallIP(ip) + n, err := ValidateFirewallIP(ip) if err != nil { return fmt.Errorf("destination error on index %d: %s", i, err) } @@ -96,7 +96,7 @@ var AddRuleCmd = base.Cmd{ case hcloud.FirewallRuleDirectionIn: rule.SourceIPs = make([]net.IPNet, len(sourceIPs)) for i, ip := range sourceIPs { - n, err := validateFirewallIP(ip) + n, err := ValidateFirewallIP(ip) if err != nil { return fmt.Errorf("source ips error on index %d: %s", i, err) } diff --git a/internal/cmd/firewall/add_rule_test.go b/internal/cmd/firewall/add_rule_test.go index 10d3f256..002a29ea 100644 --- a/internal/cmd/firewall/add_rule_test.go +++ b/internal/cmd/firewall/add_rule_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,19 +16,19 @@ func TestAddRule(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AddRuleCmd.CobraCommand(fx.State()) + cmd := firewall.AddRuleCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - SetRules(gomock.Any(), firewall, hcloud.FirewallSetRulesOpts{ + SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{ Rules: []hcloud.FirewallRule{{ Direction: hcloud.FirewallRuleDirectionIn, SourceIPs: []net.IPNet{{IP: net.IP{0, 0, 0, 0}, Mask: net.IPMask{0, 0, 0, 0}}}, diff --git a/internal/cmd/firewall/apply_to_resource_test.go b/internal/cmd/firewall/apply_to_resource_test.go index 67995c92..e5ed6491 100644 --- a/internal/cmd/firewall/apply_to_resource_test.go +++ b/internal/cmd/firewall/apply_to_resource_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,22 +15,22 @@ func TestApplyToServer(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ApplyToResourceCmd.CobraCommand(fx.State()) + cmd := firewall.ApplyToResourceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.ServerClient.EXPECT(). Get(gomock.Any(), "my-server"). Return(&hcloud.Server{ID: 456}, nil, nil) fx.Client.FirewallClient.EXPECT(). - ApplyResources(gomock.Any(), firewall, []hcloud.FirewallResource{{ + ApplyResources(gomock.Any(), fw, []hcloud.FirewallResource{{ Type: hcloud.FirewallResourceTypeServer, Server: &hcloud.FirewallResourceServer{ ID: 456, @@ -52,19 +53,19 @@ func TestApplyToLabelSelector(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ApplyToResourceCmd.CobraCommand(fx.State()) + cmd := firewall.ApplyToResourceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - ApplyResources(gomock.Any(), firewall, []hcloud.FirewallResource{{ + ApplyResources(gomock.Any(), fw, []hcloud.FirewallResource{{ Type: hcloud.FirewallResourceTypeLabelSelector, LabelSelector: &hcloud.FirewallResourceLabelSelector{ Selector: "my-label", diff --git a/internal/cmd/firewall/create_test.go b/internal/cmd/firewall/create_test.go index 90e4068d..6d49aedf 100644 --- a/internal/cmd/firewall/create_test.go +++ b/internal/cmd/firewall/create_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( _ "embed" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -20,7 +21,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := firewall.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). @@ -50,7 +51,7 @@ func TestCreateJSON(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := firewall.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 59e5d66a..69577e49 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -86,7 +86,7 @@ var DeleteRuleCmd = base.Cmd{ case hcloud.FirewallRuleDirectionOut: rule.DestinationIPs = make([]net.IPNet, len(destinationIPs)) for i, ip := range destinationIPs { - n, err := validateFirewallIP(ip) + n, err := ValidateFirewallIP(ip) if err != nil { return fmt.Errorf("destination ips error on index %d: %s", i, err) } @@ -96,7 +96,7 @@ var DeleteRuleCmd = base.Cmd{ case hcloud.FirewallRuleDirectionIn: rule.SourceIPs = make([]net.IPNet, len(sourceIPs)) for i, ip := range sourceIPs { - n, err := validateFirewallIP(ip) + n, err := ValidateFirewallIP(ip) if err != nil { return fmt.Errorf("source ips error on index %d: %s", i, err) } diff --git a/internal/cmd/firewall/delete_rule_test.go b/internal/cmd/firewall/delete_rule_test.go index 47d8f9e2..2eae690b 100644 --- a/internal/cmd/firewall/delete_rule_test.go +++ b/internal/cmd/firewall/delete_rule_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,10 +16,10 @@ func TestDeleteRule(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteRuleCmd.CobraCommand(fx.State()) + cmd := firewall.DeleteRuleCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", Rules: []hcloud.FirewallRule{{ @@ -33,9 +34,9 @@ func TestDeleteRule(t *testing.T) { fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - SetRules(gomock.Any(), firewall, hcloud.FirewallSetRulesOpts{Rules: nil}). + SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: nil}). Return([]*hcloud.Action{{ID: 123}, {ID: 321}}, nil, nil) fx.ActionWaiter.EXPECT(). WaitForActions(gomock.Any(), gomock.Any(), []*hcloud.Action{{ID: 123}, {ID: 321}}). diff --git a/internal/cmd/firewall/delete_test.go b/internal/cmd/firewall/delete_test.go index ebc7c4da..be01d40c 100644 --- a/internal/cmd/firewall/delete_test.go +++ b/internal/cmd/firewall/delete_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,19 +15,19 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := firewall.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - Delete(gomock.Any(), firewall). + Delete(gomock.Any(), fw). Return(nil, nil) out, _, err := fx.Run(cmd, []string{"test"}) diff --git a/internal/cmd/firewall/describe_test.go b/internal/cmd/firewall/describe_test.go index aef61a0f..6b6e25c8 100644 --- a/internal/cmd/firewall/describe_test.go +++ b/internal/cmd/firewall/describe_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -20,10 +21,10 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := firewall.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", Rules: []hcloud.FirewallRule{ @@ -50,7 +51,7 @@ func TestDescribe(t *testing.T) { fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.ServerClient.EXPECT(). ServerName(int64(321)). Return("myServer") @@ -72,7 +73,7 @@ Applied To: - Type: server Server ID: 321 Server Name: myServer -`, util.Datetime(firewall.Created), humanize.Time(firewall.Created)) +`, util.Datetime(fw.Created), humanize.Time(fw.Created)) assert.NoError(t, err) assert.Equal(t, expOut, out) diff --git a/internal/cmd/firewall/labels_test.go b/internal/cmd/firewall/labels_test.go index 9e55df3f..d1294e41 100644 --- a/internal/cmd/firewall/labels_test.go +++ b/internal/cmd/firewall/labels_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := firewall.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := firewall.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). diff --git a/internal/cmd/firewall/list_test.go b/internal/cmd/firewall/list_test.go index 640cf74b..7bb7ddb2 100644 --- a/internal/cmd/firewall/list_test.go +++ b/internal/cmd/firewall/list_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := firewall.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). diff --git a/internal/cmd/firewall/remove_from_resource_test.go b/internal/cmd/firewall/remove_from_resource_test.go index 26825eea..92d99063 100644 --- a/internal/cmd/firewall/remove_from_resource_test.go +++ b/internal/cmd/firewall/remove_from_resource_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,22 +15,22 @@ func TestRemoveFromServer(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := RemoveFromResourceCmd.CobraCommand(fx.State()) + cmd := firewall.RemoveFromResourceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.ServerClient.EXPECT(). Get(gomock.Any(), "my-server"). Return(&hcloud.Server{ID: 456}, nil, nil) fx.Client.FirewallClient.EXPECT(). - RemoveResources(gomock.Any(), firewall, []hcloud.FirewallResource{{ + RemoveResources(gomock.Any(), fw, []hcloud.FirewallResource{{ Type: hcloud.FirewallResourceTypeServer, Server: &hcloud.FirewallResourceServer{ ID: 456, @@ -52,19 +53,19 @@ func TestRemoveFromLabelSelector(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := RemoveFromResourceCmd.CobraCommand(fx.State()) + cmd := firewall.RemoveFromResourceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - RemoveResources(gomock.Any(), firewall, []hcloud.FirewallResource{{ + RemoveResources(gomock.Any(), fw, []hcloud.FirewallResource{{ Type: hcloud.FirewallResourceTypeLabelSelector, LabelSelector: &hcloud.FirewallResourceLabelSelector{ Selector: "my-label", diff --git a/internal/cmd/firewall/replace_rules_test.go b/internal/cmd/firewall/replace_rules_test.go index da53139e..2fcdfbfe 100644 --- a/internal/cmd/firewall/replace_rules_test.go +++ b/internal/cmd/firewall/replace_rules_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,19 +16,19 @@ func TestReplaceRules(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ReplaceRulesCmd.CobraCommand(fx.State()) + cmd := firewall.ReplaceRulesCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - firewall := &hcloud.Firewall{ + fw := &hcloud.Firewall{ ID: 123, Name: "test", } fx.Client.FirewallClient.EXPECT(). Get(gomock.Any(), "test"). - Return(firewall, nil, nil) + Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - SetRules(gomock.Any(), firewall, hcloud.FirewallSetRulesOpts{ + SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{ Rules: []hcloud.FirewallRule{ { Direction: hcloud.FirewallRuleDirectionIn, diff --git a/internal/cmd/firewall/update_test.go b/internal/cmd/firewall/update_test.go index b71029a9..437d5b5f 100644 --- a/internal/cmd/firewall/update_test.go +++ b/internal/cmd/firewall/update_test.go @@ -1,4 +1,4 @@ -package firewall +package firewall_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := firewall.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FirewallClient.EXPECT(). diff --git a/internal/cmd/firewall/validation.go b/internal/cmd/firewall/validation.go index 1a7bb15e..0ae7b73f 100644 --- a/internal/cmd/firewall/validation.go +++ b/internal/cmd/firewall/validation.go @@ -5,7 +5,7 @@ import ( "net" ) -func validateFirewallIP(ip string) (*net.IPNet, error) { +func ValidateFirewallIP(ip string) (*net.IPNet, error) { i, n, err := net.ParseCIDR(ip) if err != nil { return nil, fmt.Errorf("%s", err) diff --git a/internal/cmd/firewall/validation_test.go b/internal/cmd/firewall/validation_test.go index a1393cf1..18ec5750 100644 --- a/internal/cmd/firewall/validation_test.go +++ b/internal/cmd/firewall/validation_test.go @@ -1,10 +1,12 @@ -package firewall +package firewall_test import ( "fmt" "testing" "github.com/stretchr/testify/assert" + + "github.com/hetznercloud/cli/internal/cmd/firewall" ) func TestValidateFirewallIP(t *testing.T) { @@ -49,7 +51,7 @@ func TestValidateFirewallIP(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - net, err := validateFirewallIP(test.ip) + net, err := firewall.ValidateFirewallIP(test.ip) if test.err != nil { assert.Equal(t, err, test.err) diff --git a/internal/cmd/floatingip/assign_test.go b/internal/cmd/floatingip/assign_test.go index 8f6871b4..a20baecb 100644 --- a/internal/cmd/floatingip/assign_test.go +++ b/internal/cmd/floatingip/assign_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestAssign(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AssignCmd.CobraCommand(fx.State()) + cmd := floatingip.AssignCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/create_test.go b/internal/cmd/floatingip/create_test.go index 608d3bf0..330d7b8d 100644 --- a/internal/cmd/floatingip/create_test.go +++ b/internal/cmd/floatingip/create_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( _ "embed" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -19,7 +20,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := floatingip.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). @@ -54,7 +55,7 @@ func TestCreateJSON(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := floatingip.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). @@ -90,7 +91,7 @@ func TestCreateProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := floatingip.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() floatingIp := &hcloud.FloatingIP{ diff --git a/internal/cmd/floatingip/delete_test.go b/internal/cmd/floatingip/delete_test.go index 6e3bfcce..585ad49e 100644 --- a/internal/cmd/floatingip/delete_test.go +++ b/internal/cmd/floatingip/delete_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := floatingip.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() floatingIP := &hcloud.FloatingIP{ diff --git a/internal/cmd/floatingip/describe_test.go b/internal/cmd/floatingip/describe_test.go index 2dae550f..afe48746 100644 --- a/internal/cmd/floatingip/describe_test.go +++ b/internal/cmd/floatingip/describe_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "fmt" @@ -10,6 +10,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -21,7 +22,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := floatingip.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() floatingIP := &hcloud.FloatingIP{ diff --git a/internal/cmd/floatingip/disable_protection_test.go b/internal/cmd/floatingip/disable_protection_test.go index 82a7ee25..4cfd50ef 100644 --- a/internal/cmd/floatingip/disable_protection_test.go +++ b/internal/cmd/floatingip/disable_protection_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDisableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DisableProtectionCmd.CobraCommand(fx.State()) + cmd := floatingip.DisableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/enable_protection_test.go b/internal/cmd/floatingip/enable_protection_test.go index c0de258b..c5424938 100644 --- a/internal/cmd/floatingip/enable_protection_test.go +++ b/internal/cmd/floatingip/enable_protection_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestEnableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := EnableProtectionCmd.CobraCommand(fx.State()) + cmd := floatingip.EnableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/labels_test.go b/internal/cmd/floatingip/labels_test.go index 1fc1a980..122971ec 100644 --- a/internal/cmd/floatingip/labels_test.go +++ b/internal/cmd/floatingip/labels_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := floatingip.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := floatingip.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/list_test.go b/internal/cmd/floatingip/list_test.go index 723a2d2a..36c21be7 100644 --- a/internal/cmd/floatingip/list_test.go +++ b/internal/cmd/floatingip/list_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "net" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -18,7 +19,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := floatingip.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/set_rdns_test.go b/internal/cmd/floatingip/set_rdns_test.go index 7ffec61b..3e14285a 100644 --- a/internal/cmd/floatingip/set_rdns_test.go +++ b/internal/cmd/floatingip/set_rdns_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestSetRDNS(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := SetRDNSCmd.CobraCommand(fx.State()) + cmd := floatingip.SetRDNSCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() floatingIP := &hcloud.FloatingIP{ diff --git a/internal/cmd/floatingip/unassign_test.go b/internal/cmd/floatingip/unassign_test.go index d3f07355..ba63ac17 100644 --- a/internal/cmd/floatingip/unassign_test.go +++ b/internal/cmd/floatingip/unassign_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUnassign(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UnassignCmd.CobraCommand(fx.State()) + cmd := floatingip.UnassignCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/floatingip/update_test.go b/internal/cmd/floatingip/update_test.go index 9f7c3eea..944dec79 100644 --- a/internal/cmd/floatingip/update_test.go +++ b/internal/cmd/floatingip/update_test.go @@ -1,4 +1,4 @@ -package floatingip +package floatingip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := floatingip.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). @@ -37,7 +38,7 @@ func TestUpdateDescription(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := floatingip.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.FloatingIPClient.EXPECT(). diff --git a/internal/cmd/image/delete_test.go b/internal/cmd/image/delete_test.go index 62af9a30..48c1ab7a 100644 --- a/internal/cmd/image/delete_test.go +++ b/internal/cmd/image/delete_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,19 +15,19 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := image.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - image := &hcloud.Image{ + img := &hcloud.Image{ ID: 123, Name: "test", } fx.Client.ImageClient.EXPECT(). Get(gomock.Any(), "test"). - Return(image, nil, nil) + Return(img, nil, nil) fx.Client.ImageClient.EXPECT(). - Delete(gomock.Any(), image). + Delete(gomock.Any(), img). Return(nil, nil) out, _, err := fx.Run(cmd, []string{"test"}) diff --git a/internal/cmd/image/describe_test.go b/internal/cmd/image/describe_test.go index 2e41d9d1..2b49a25e 100644 --- a/internal/cmd/image/describe_test.go +++ b/internal/cmd/image/describe_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -20,7 +21,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := image.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() img := &hcloud.Image{ diff --git a/internal/cmd/image/disable_protection_test.go b/internal/cmd/image/disable_protection_test.go index 86e93efc..ba9dbffd 100644 --- a/internal/cmd/image/disable_protection_test.go +++ b/internal/cmd/image/disable_protection_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDisableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DisableProtectionCmd.CobraCommand(fx.State()) + cmd := image.DisableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). diff --git a/internal/cmd/image/enable_protection_test.go b/internal/cmd/image/enable_protection_test.go index d084e176..ca01e7c3 100644 --- a/internal/cmd/image/enable_protection_test.go +++ b/internal/cmd/image/enable_protection_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestEnableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := EnableProtectionCmd.CobraCommand(fx.State()) + cmd := image.EnableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). diff --git a/internal/cmd/image/labels_test.go b/internal/cmd/image/labels_test.go index d7c70c70..0684ca04 100644 --- a/internal/cmd/image/labels_test.go +++ b/internal/cmd/image/labels_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := image.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := image.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). diff --git a/internal/cmd/image/list_test.go b/internal/cmd/image/list_test.go index b3b97f1b..6e96c8cb 100644 --- a/internal/cmd/image/list_test.go +++ b/internal/cmd/image/list_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := image.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). diff --git a/internal/cmd/image/update_test.go b/internal/cmd/image/update_test.go index 24573105..1447024e 100644 --- a/internal/cmd/image/update_test.go +++ b/internal/cmd/image/update_test.go @@ -1,4 +1,4 @@ -package image +package image_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateDescription(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := image.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). @@ -37,7 +38,7 @@ func TestUpdateType(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := image.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ImageClient.EXPECT(). diff --git a/internal/cmd/iso/describe_test.go b/internal/cmd/iso/describe_test.go index 0b5ac71e..f33d6123 100644 --- a/internal/cmd/iso/describe_test.go +++ b/internal/cmd/iso/describe_test.go @@ -1,4 +1,4 @@ -package iso +package iso_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/iso" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDescribe(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := iso.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ISOClient.EXPECT(). diff --git a/internal/cmd/iso/list_test.go b/internal/cmd/iso/list_test.go index fa0c400d..c2bc0504 100644 --- a/internal/cmd/iso/list_test.go +++ b/internal/cmd/iso/list_test.go @@ -1,4 +1,4 @@ -package iso +package iso_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/iso" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := iso.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ISOClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/add_service_test.go b/internal/cmd/loadbalancer/add_service_test.go index 4f281ce8..0924efaf 100644 --- a/internal/cmd/loadbalancer/add_service_test.go +++ b/internal/cmd/loadbalancer/add_service_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestAddService(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AddServiceCmd.CobraCommand(fx.State()) + cmd := loadbalancer.AddServiceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/add_target_test.go b/internal/cmd/loadbalancer/add_target_test.go index 50b69d92..14d0ad87 100644 --- a/internal/cmd/loadbalancer/add_target_test.go +++ b/internal/cmd/loadbalancer/add_target_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestAddTargetServer(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AddTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.AddTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -46,7 +47,7 @@ func TestAddTargetLabelSelector(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AddTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.AddTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -74,7 +75,7 @@ func TestAddTargetIP(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AddTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.AddTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/attach_to_network_test.go b/internal/cmd/loadbalancer/attach_to_network_test.go index e9a7a90f..c26d32dd 100644 --- a/internal/cmd/loadbalancer/attach_to_network_test.go +++ b/internal/cmd/loadbalancer/attach_to_network_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestAttachToNetwork(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AttachToNetworkCmd.CobraCommand(fx.State()) + cmd := loadbalancer.AttachToNetworkCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/change_algorithm_test.go b/internal/cmd/loadbalancer/change_algorithm_test.go index 4ba64ca5..5499ced1 100644 --- a/internal/cmd/loadbalancer/change_algorithm_test.go +++ b/internal/cmd/loadbalancer/change_algorithm_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestChangeAlgorithm(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ChangeAlgorithmCmd.CobraCommand(fx.State()) + cmd := loadbalancer.ChangeAlgorithmCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/change_type_test.go b/internal/cmd/loadbalancer/change_type_test.go index a0c8f550..e1a0b669 100644 --- a/internal/cmd/loadbalancer/change_type_test.go +++ b/internal/cmd/loadbalancer/change_type_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestChangeType(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ChangeTypeCmd.CobraCommand(fx.State()) + cmd := loadbalancer.ChangeTypeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() lbType := &hcloud.LoadBalancerType{ID: 321, Name: "lb21"} diff --git a/internal/cmd/loadbalancer/create_test.go b/internal/cmd/loadbalancer/create_test.go index 91c424f2..0fa8a220 100644 --- a/internal/cmd/loadbalancer/create_test.go +++ b/internal/cmd/loadbalancer/create_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( _ "embed" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -20,7 +21,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := loadbalancer.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -64,7 +65,7 @@ func TestCreateJSON(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := loadbalancer.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() lb := &hcloud.LoadBalancer{ @@ -114,7 +115,7 @@ func TestCreateProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := loadbalancer.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() loadBalancer := &hcloud.LoadBalancer{ diff --git a/internal/cmd/loadbalancer/delete_service_test.go b/internal/cmd/loadbalancer/delete_service_test.go index 9f075a9e..e26f151f 100644 --- a/internal/cmd/loadbalancer/delete_service_test.go +++ b/internal/cmd/loadbalancer/delete_service_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDeleteService(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteServiceCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DeleteServiceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/delete_test.go b/internal/cmd/loadbalancer/delete_test.go index 3088652f..36de7cd1 100644 --- a/internal/cmd/loadbalancer/delete_test.go +++ b/internal/cmd/loadbalancer/delete_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() loadBalancer := &hcloud.LoadBalancer{ diff --git a/internal/cmd/loadbalancer/describe_test.go b/internal/cmd/loadbalancer/describe_test.go index d4ac947e..d1e3bdd8 100644 --- a/internal/cmd/loadbalancer/describe_test.go +++ b/internal/cmd/loadbalancer/describe_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "fmt" @@ -10,6 +10,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -21,7 +22,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() lb := &hcloud.LoadBalancer{ diff --git a/internal/cmd/loadbalancer/detach_from_network_test.go b/internal/cmd/loadbalancer/detach_from_network_test.go index 48483168..fd4c8142 100644 --- a/internal/cmd/loadbalancer/detach_from_network_test.go +++ b/internal/cmd/loadbalancer/detach_from_network_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDetachFromNetwork(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DetachFromNetworkCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DetachFromNetworkCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/disable_protection_test.go b/internal/cmd/loadbalancer/disable_protection_test.go index b2591aa9..e7d829fd 100644 --- a/internal/cmd/loadbalancer/disable_protection_test.go +++ b/internal/cmd/loadbalancer/disable_protection_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDisableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DisableProtectionCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DisableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/disable_public_interface_test.go b/internal/cmd/loadbalancer/disable_public_interface_test.go index 22bcd699..2587f0f7 100644 --- a/internal/cmd/loadbalancer/disable_public_interface_test.go +++ b/internal/cmd/loadbalancer/disable_public_interface_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDisablePublicInterface(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DisablePublicInterfaceCmd.CobraCommand(fx.State()) + cmd := loadbalancer.DisablePublicInterfaceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/enable_protection_test.go b/internal/cmd/loadbalancer/enable_protection_test.go index 62e0dc6b..e4dd2177 100644 --- a/internal/cmd/loadbalancer/enable_protection_test.go +++ b/internal/cmd/loadbalancer/enable_protection_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestEnableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := EnableProtectionCmd.CobraCommand(fx.State()) + cmd := loadbalancer.EnableProtectionCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/enable_public_interface_test.go b/internal/cmd/loadbalancer/enable_public_interface_test.go index 254aa352..43033f7e 100644 --- a/internal/cmd/loadbalancer/enable_public_interface_test.go +++ b/internal/cmd/loadbalancer/enable_public_interface_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestEnablePublicInterface(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := EnablePublicInterfaceCmd.CobraCommand(fx.State()) + cmd := loadbalancer.EnablePublicInterfaceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/labels_test.go b/internal/cmd/loadbalancer/labels_test.go index 9ea8dc80..9a72d32b 100644 --- a/internal/cmd/loadbalancer/labels_test.go +++ b/internal/cmd/loadbalancer/labels_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := loadbalancer.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := loadbalancer.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/list.go b/internal/cmd/loadbalancer/list.go index 226d8a6d..3039143a 100644 --- a/internal/cmd/loadbalancer/list.go +++ b/internal/cmd/loadbalancer/list.go @@ -78,7 +78,7 @@ var ListCmd = base.ListCmd{ })). AddFieldFn("health", output.FieldFn(func(obj interface{}) string { loadBalancer := obj.(*hcloud.LoadBalancer) - return loadBalancerHealth(loadBalancer) + return Health(loadBalancer) })) }, @@ -92,7 +92,7 @@ var ListCmd = base.ListCmd{ }, } -func loadBalancerHealth(l *hcloud.LoadBalancer) string { +func Health(l *hcloud.LoadBalancer) string { healthyCount := 0 unhealthyCount := 0 unknownCount := 0 diff --git a/internal/cmd/loadbalancer/list_test.go b/internal/cmd/loadbalancer/list_test.go index 40a974ad..e647ac7f 100644 --- a/internal/cmd/loadbalancer/list_test.go +++ b/internal/cmd/loadbalancer/list_test.go @@ -1,10 +1,11 @@ -package loadbalancer +package loadbalancer_test import ( "testing" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -197,7 +198,7 @@ func TestLoadBalancerHealth(t *testing.T) { } for _, test := range tests { - res := loadBalancerHealth(test.lb) + res := loadbalancer.Health(test.lb) assert.Equal(t, test.expected, res, test.name) } } diff --git a/internal/cmd/loadbalancer/metrics_test.go b/internal/cmd/loadbalancer/metrics_test.go index 21c5c880..a8f1ad13 100644 --- a/internal/cmd/loadbalancer/metrics_test.go +++ b/internal/cmd/loadbalancer/metrics_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestMetrics(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := MetricsCmd.CobraCommand(fx.State()) + cmd := loadbalancer.MetricsCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() start := time.Date(2022, 11, 1, 0, 0, 0, 0, time.UTC) diff --git a/internal/cmd/loadbalancer/remove_target_test.go b/internal/cmd/loadbalancer/remove_target_test.go index 2a832650..bd08a8be 100644 --- a/internal/cmd/loadbalancer/remove_target_test.go +++ b/internal/cmd/loadbalancer/remove_target_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestRemoveTargetServer(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := RemoveTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.RemoveTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -43,7 +44,7 @@ func TestRemoveTargetLabelSelector(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := RemoveTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.RemoveTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). @@ -68,7 +69,7 @@ func TestRemoveTargetIP(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := RemoveTargetCmd.CobraCommand(fx.State()) + cmd := loadbalancer.RemoveTargetCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/set_rdns_test.go b/internal/cmd/loadbalancer/set_rdns_test.go index 3fbf1761..6b8a91fd 100644 --- a/internal/cmd/loadbalancer/set_rdns_test.go +++ b/internal/cmd/loadbalancer/set_rdns_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "net" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestSetRDNS(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := SetRDNSCmd.CobraCommand(fx.State()) + cmd := loadbalancer.SetRDNSCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() loadBalancer := &hcloud.LoadBalancer{ diff --git a/internal/cmd/loadbalancer/update_service_test.go b/internal/cmd/loadbalancer/update_service_test.go index 544491c4..246ff2cf 100644 --- a/internal/cmd/loadbalancer/update_service_test.go +++ b/internal/cmd/loadbalancer/update_service_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestUpdateService(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateServiceCmd.CobraCommand(fx.State()) + cmd := loadbalancer.UpdateServiceCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancer/update_test.go b/internal/cmd/loadbalancer/update_test.go index cd1d6b2b..f597d110 100644 --- a/internal/cmd/loadbalancer/update_test.go +++ b/internal/cmd/loadbalancer/update_test.go @@ -1,4 +1,4 @@ -package loadbalancer +package loadbalancer_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := loadbalancer.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerClient.EXPECT(). diff --git a/internal/cmd/loadbalancertype/describe_test.go b/internal/cmd/loadbalancertype/describe_test.go index 460bfff0..1565a071 100644 --- a/internal/cmd/loadbalancertype/describe_test.go +++ b/internal/cmd/loadbalancertype/describe_test.go @@ -1,4 +1,4 @@ -package loadbalancertype +package loadbalancertype_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancertype" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDescribe(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := loadbalancertype.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerTypeClient.EXPECT(). diff --git a/internal/cmd/loadbalancertype/list_test.go b/internal/cmd/loadbalancertype/list_test.go index 5c8c7c66..c89ac245 100644 --- a/internal/cmd/loadbalancertype/list_test.go +++ b/internal/cmd/loadbalancertype/list_test.go @@ -1,4 +1,4 @@ -package loadbalancertype +package loadbalancertype_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/loadbalancertype" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := loadbalancertype.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LoadBalancerTypeClient.EXPECT(). diff --git a/internal/cmd/location/list_test.go b/internal/cmd/location/list_test.go index 117f21b0..d9052527 100644 --- a/internal/cmd/location/list_test.go +++ b/internal/cmd/location/list_test.go @@ -1,4 +1,4 @@ -package location +package location_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/location" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := location.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.LocationClient.EXPECT(). diff --git a/internal/cmd/network/create_test.go b/internal/cmd/network/create_test.go index e714fc66..e260ae9a 100644 --- a/internal/cmd/network/create_test.go +++ b/internal/cmd/network/create_test.go @@ -1,4 +1,4 @@ -package network +package network_test import ( _ "embed" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -20,7 +21,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := network.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() _, ipRange, _ := net.ParseCIDR("10.0.0.0/24") @@ -50,7 +51,7 @@ func TestCreateJSON(t *testing.T) { time.Local = time.UTC - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := network.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() _, ipRange, _ := net.ParseCIDR("10.0.0.0/24") @@ -84,11 +85,11 @@ func TestCreateProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := network.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() _, ipRange, _ := net.ParseCIDR("10.0.0.0/24") - network := &hcloud.Network{ + n := &hcloud.Network{ ID: 123, Name: "myNetwork", IPRange: ipRange, @@ -100,9 +101,9 @@ func TestCreateProtection(t *testing.T) { IPRange: ipRange, Labels: make(map[string]string), }). - Return(network, nil, nil) + Return(n, nil, nil) fx.Client.NetworkClient.EXPECT(). - ChangeProtection(gomock.Any(), network, hcloud.NetworkChangeProtectionOpts{ + ChangeProtection(gomock.Any(), n, hcloud.NetworkChangeProtectionOpts{ Delete: hcloud.Ptr(true), }). Return(&hcloud.Action{ID: 123}, nil, nil) diff --git a/internal/cmd/network/delete_test.go b/internal/cmd/network/delete_test.go index bd0bf729..2dec6404 100644 --- a/internal/cmd/network/delete_test.go +++ b/internal/cmd/network/delete_test.go @@ -1,4 +1,4 @@ -package network +package network_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,19 +15,19 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := network.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - network := &hcloud.Network{ + n := &hcloud.Network{ ID: 123, Name: "test", } fx.Client.NetworkClient.EXPECT(). Get(gomock.Any(), "test"). - Return(network, nil, nil) + Return(n, nil, nil) fx.Client.NetworkClient.EXPECT(). - Delete(gomock.Any(), network). + Delete(gomock.Any(), n). Return(nil, nil) out, _, err := fx.Run(cmd, []string{"test"}) diff --git a/internal/cmd/network/describe_test.go b/internal/cmd/network/describe_test.go index f6e3627a..40a80375 100644 --- a/internal/cmd/network/describe_test.go +++ b/internal/cmd/network/describe_test.go @@ -1,4 +1,4 @@ -package network +package network_test import ( "fmt" @@ -10,6 +10,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -21,10 +22,10 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := network.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - network := &hcloud.Network{ + n := &hcloud.Network{ ID: 123, Name: "test", Created: time.Date(2036, 8, 12, 12, 0, 0, 0, time.UTC), @@ -35,7 +36,7 @@ func TestDescribe(t *testing.T) { fx.Client.NetworkClient.EXPECT(). Get(gomock.Any(), "test"). - Return(network, nil, nil) + Return(n, nil, nil) out, _, err := fx.Run(cmd, []string{"test"}) @@ -52,7 +53,7 @@ Protection: Delete: yes Labels: key: value -`, util.Datetime(network.Created), humanize.Time(network.Created)) +`, util.Datetime(n.Created), humanize.Time(n.Created)) assert.NoError(t, err) assert.Equal(t, expOut, out) diff --git a/internal/cmd/network/labels_test.go b/internal/cmd/network/labels_test.go index 52058b22..ebe40826 100644 --- a/internal/cmd/network/labels_test.go +++ b/internal/cmd/network/labels_test.go @@ -1,4 +1,4 @@ -package network +package network_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := network.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.NetworkClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := network.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.NetworkClient.EXPECT(). diff --git a/internal/cmd/network/update_test.go b/internal/cmd/network/update_test.go index 48e8f5ce..7b203587 100644 --- a/internal/cmd/network/update_test.go +++ b/internal/cmd/network/update_test.go @@ -1,4 +1,4 @@ -package network +package network_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := network.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.NetworkClient.EXPECT(). diff --git a/internal/cmd/placementgroup/labels_test.go b/internal/cmd/placementgroup/labels_test.go index 83c3f53f..481921d5 100644 --- a/internal/cmd/placementgroup/labels_test.go +++ b/internal/cmd/placementgroup/labels_test.go @@ -1,4 +1,4 @@ -package placementgroup +package placementgroup_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := placementgroup.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PlacementGroupClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := placementgroup.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PlacementGroupClient.EXPECT(). diff --git a/internal/cmd/placementgroup/update_test.go b/internal/cmd/placementgroup/update_test.go index d3a5574c..16562632 100644 --- a/internal/cmd/placementgroup/update_test.go +++ b/internal/cmd/placementgroup/update_test.go @@ -1,4 +1,4 @@ -package placementgroup +package placementgroup_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := placementgroup.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PlacementGroupClient.EXPECT(). diff --git a/internal/cmd/primaryip/assign_test.go b/internal/cmd/primaryip/assign_test.go index 54332f27..0a45bec8 100644 --- a/internal/cmd/primaryip/assign_test.go +++ b/internal/cmd/primaryip/assign_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,7 +16,7 @@ func TestAssign(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := AssignCmd.CobraCommand(fx.State()) + cmd := primaryip.AssignCmd.CobraCommand(fx.State()) action := &hcloud.Action{ID: 1} fx.ExpectEnsureToken() var ( diff --git a/internal/cmd/primaryip/changedns_test.go b/internal/cmd/primaryip/changedns_test.go index 8d79107c..0efdf422 100644 --- a/internal/cmd/primaryip/changedns_test.go +++ b/internal/cmd/primaryip/changedns_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestChangeDNS(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ChangeDNSCmd.CobraCommand(fx.State()) + cmd := primaryip.ChangeDNSCmd.CobraCommand(fx.State()) action := &hcloud.Action{ID: 1} fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/primaryip/create_test.go b/internal/cmd/primaryip/create_test.go index 9512b100..ac5d18c2 100644 --- a/internal/cmd/primaryip/create_test.go +++ b/internal/cmd/primaryip/create_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( _ "embed" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -20,7 +21,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := primaryip.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). Create( @@ -64,7 +65,7 @@ func TestCreateJSON(t *testing.T) { time.Local = time.UTC - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := primaryip.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/primaryip/delete_test.go b/internal/cmd/primaryip/delete_test.go index 567fa758..019fc36a 100644 --- a/internal/cmd/primaryip/delete_test.go +++ b/internal/cmd/primaryip/delete_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,8 +15,8 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) - primaryip := &hcloud.PrimaryIP{ID: 13} + cmd := primaryip.DeleteCmd.CobraCommand(fx.State()) + ip := &hcloud.PrimaryIP{ID: 13} fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). Get( @@ -23,14 +24,14 @@ func TestDelete(t *testing.T) { "13", ). Return( - primaryip, + ip, &hcloud.Response{}, nil, ) fx.Client.PrimaryIPClient.EXPECT(). Delete( gomock.Any(), - primaryip, + ip, ). Return( &hcloud.Response{}, diff --git a/internal/cmd/primaryip/describe_test.go b/internal/cmd/primaryip/describe_test.go index 4f16923c..d226524b 100644 --- a/internal/cmd/primaryip/describe_test.go +++ b/internal/cmd/primaryip/describe_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "fmt" @@ -10,6 +10,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -21,7 +22,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := primaryip.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() primaryIP := &hcloud.PrimaryIP{ diff --git a/internal/cmd/primaryip/disable_protection_test.go b/internal/cmd/primaryip/disable_protection_test.go index bab9f567..02386098 100644 --- a/internal/cmd/primaryip/disable_protection_test.go +++ b/internal/cmd/primaryip/disable_protection_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,9 +15,9 @@ func TestEnable(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DisableProtectionCmd.CobraCommand(fx.State()) + cmd := primaryip.DisableProtectionCmd.CobraCommand(fx.State()) action := &hcloud.Action{ID: 1} - primaryip := &hcloud.PrimaryIP{ID: 13} + ip := &hcloud.PrimaryIP{ID: 13} fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). Get( @@ -24,7 +25,7 @@ func TestEnable(t *testing.T) { "13", ). Return( - primaryip, + ip, &hcloud.Response{}, nil, ) diff --git a/internal/cmd/primaryip/enable_protection_test.go b/internal/cmd/primaryip/enable_protection_test.go index 141f9811..765d8f8e 100644 --- a/internal/cmd/primaryip/enable_protection_test.go +++ b/internal/cmd/primaryip/enable_protection_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,9 +15,9 @@ func TestEnableProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := EnableProtectionCmd.CobraCommand(fx.State()) + cmd := primaryip.EnableProtectionCmd.CobraCommand(fx.State()) action := &hcloud.Action{ID: 1} - primaryip := &hcloud.PrimaryIP{ID: 13} + ip := &hcloud.PrimaryIP{ID: 13} fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). Get( @@ -24,7 +25,7 @@ func TestEnableProtection(t *testing.T) { "13", ). Return( - primaryip, + ip, &hcloud.Response{}, nil, ) diff --git a/internal/cmd/primaryip/labels_test.go b/internal/cmd/primaryip/labels_test.go index 4aa5ab77..4e1dbeaa 100644 --- a/internal/cmd/primaryip/labels_test.go +++ b/internal/cmd/primaryip/labels_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := primaryip.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := primaryip.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/primaryip/list_test.go b/internal/cmd/primaryip/list_test.go index 31dde821..3fe8a7f5 100644 --- a/internal/cmd/primaryip/list_test.go +++ b/internal/cmd/primaryip/list_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "net" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -16,7 +17,7 @@ func TestList(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ListCmd.CobraCommand(fx.State()) + cmd := primaryip.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/primaryip/primaryip.go b/internal/cmd/primaryip/primaryip.go index 21db646a..ac2a29cf 100644 --- a/internal/cmd/primaryip/primaryip.go +++ b/internal/cmd/primaryip/primaryip.go @@ -18,7 +18,7 @@ func NewCommand(s state.State) *cobra.Command { ListCmd.CobraCommand(s), DescribeCmd.CobraCommand(s), CreateCmd.CobraCommand(s), - updateCmd.CobraCommand(s), + UpdateCmd.CobraCommand(s), DeleteCmd.CobraCommand(s), AssignCmd.CobraCommand(s), UnAssignCmd.CobraCommand(s), diff --git a/internal/cmd/primaryip/unassign_test.go b/internal/cmd/primaryip/unassign_test.go index 8dd4feae..03ac2a09 100644 --- a/internal/cmd/primaryip/unassign_test.go +++ b/internal/cmd/primaryip/unassign_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUnAssign(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UnAssignCmd.CobraCommand(fx.State()) + cmd := primaryip.UnAssignCmd.CobraCommand(fx.State()) action := &hcloud.Action{ID: 1} fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/primaryip/update.go b/internal/cmd/primaryip/update.go index 5cb81bd7..f37116dd 100644 --- a/internal/cmd/primaryip/update.go +++ b/internal/cmd/primaryip/update.go @@ -10,7 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -var updateCmd = base.UpdateCmd{ +var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Primary IP", ShortDescription: "Update a Primary IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PrimaryIP().Names }, diff --git a/internal/cmd/primaryip/update_test.go b/internal/cmd/primaryip/update_test.go index 20c1c12e..e1956cbf 100644 --- a/internal/cmd/primaryip/update_test.go +++ b/internal/cmd/primaryip/update_test.go @@ -1,4 +1,4 @@ -package primaryip +package primaryip_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := updateCmd.CobraCommand(fx.State()) + cmd := primaryip.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). @@ -38,7 +39,7 @@ func TestUpdateAutoDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := updateCmd.CobraCommand(fx.State()) + cmd := primaryip.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.PrimaryIPClient.EXPECT(). diff --git a/internal/cmd/server/delete_test.go b/internal/cmd/server/delete_test.go index 83bfca3e..ac6a6c10 100644 --- a/internal/cmd/server/delete_test.go +++ b/internal/cmd/server/delete_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := server.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() srv := &hcloud.Server{ diff --git a/internal/cmd/server/describe_test.go b/internal/cmd/server/describe_test.go index 48b3b496..aab3ffd9 100644 --- a/internal/cmd/server/describe_test.go +++ b/internal/cmd/server/describe_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -20,7 +21,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := server.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() srv := &hcloud.Server{ diff --git a/internal/cmd/server/labels_test.go b/internal/cmd/server/labels_test.go index 03d22c53..1daf3570 100644 --- a/internal/cmd/server/labels_test.go +++ b/internal/cmd/server/labels_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := server.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := server.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). diff --git a/internal/cmd/server/list_test.go b/internal/cmd/server/list_test.go index 6c1333cf..796b0a0c 100644 --- a/internal/cmd/server/list_test.go +++ b/internal/cmd/server/list_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "net" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -18,7 +19,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := server.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). diff --git a/internal/cmd/server/remove_from_placement_group_test.go b/internal/cmd/server/remove_from_placement_group_test.go index 935f85f1..94697fdd 100644 --- a/internal/cmd/server/remove_from_placement_group_test.go +++ b/internal/cmd/server/remove_from_placement_group_test.go @@ -18,19 +18,19 @@ func TestRemoveFromPlacementGroup(t *testing.T) { cmd := server.RemoveFromPlacementGroupCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - server := hcloud.Server{ + srv := hcloud.Server{ ID: 42, Name: "my server", } fx.Client.ServerClient.EXPECT(). - Get(gomock.Any(), server.Name). - Return(&server, nil, nil) + Get(gomock.Any(), srv.Name). + Return(&srv, nil, nil) fx.Client.ServerClient.EXPECT(). - RemoveFromPlacementGroup(gomock.Any(), &server) + RemoveFromPlacementGroup(gomock.Any(), &srv) fx.ActionWaiter.EXPECT().ActionProgress(gomock.Any(), gomock.Any(), nil) - out, _, err := fx.Run(cmd, []string{server.Name}) + out, _, err := fx.Run(cmd, []string{srv.Name}) expOut := `Server 42 removed from placement group ` diff --git a/internal/cmd/server/shutdown_test.go b/internal/cmd/server/shutdown_test.go index 1ca5ba5f..ea1f8e35 100644 --- a/internal/cmd/server/shutdown_test.go +++ b/internal/cmd/server/shutdown_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -15,26 +16,24 @@ func TestShutdown(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ShutdownCmd.CobraCommand(fx.State()) + cmd := server.ShutdownCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - var ( - server = hcloud.Server{ - ID: 42, - Name: "my server", - Status: hcloud.ServerStatusRunning, - } - ) + srv := hcloud.Server{ + ID: 42, + Name: "my server", + Status: hcloud.ServerStatusRunning, + } fx.Client.ServerClient.EXPECT(). - Get(gomock.Any(), server.Name). - Return(&server, nil, nil) + Get(gomock.Any(), srv.Name). + Return(&srv, nil, nil) fx.Client.ServerClient.EXPECT(). - Shutdown(gomock.Any(), &server) + Shutdown(gomock.Any(), &srv) fx.ActionWaiter.EXPECT().ActionProgress(gomock.Any(), gomock.Any(), nil) - out, _, err := fx.Run(cmd, []string{server.Name}) + out, _, err := fx.Run(cmd, []string{srv.Name}) expOut := "Sent shutdown signal to server 42\n" @@ -47,32 +46,30 @@ func TestShutdownWait(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := ShutdownCmd.CobraCommand(fx.State()) + cmd := server.ShutdownCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - var ( - server = hcloud.Server{ - ID: 42, - Name: "my server", - Status: hcloud.ServerStatusRunning, - } - ) + srv := hcloud.Server{ + ID: 42, + Name: "my server", + Status: hcloud.ServerStatusRunning, + } fx.Client.ServerClient.EXPECT(). - Get(gomock.Any(), server.Name). - Return(&server, nil, nil) + Get(gomock.Any(), srv.Name). + Return(&srv, nil, nil) fx.Client.ServerClient.EXPECT(). - Shutdown(gomock.Any(), &server) + Shutdown(gomock.Any(), &srv) fx.ActionWaiter.EXPECT().ActionProgress(gomock.Any(), gomock.Any(), nil) fx.Client.ServerClient.EXPECT(). - GetByID(gomock.Any(), server.ID). - Return(&server, nil, nil). - Return(&server, nil, nil). - Return(&hcloud.Server{ID: server.ID, Name: server.Name, Status: hcloud.ServerStatusOff}, nil, nil) + GetByID(gomock.Any(), srv.ID). + Return(&srv, nil, nil). + Return(&srv, nil, nil). + Return(&hcloud.Server{ID: srv.ID, Name: srv.Name, Status: hcloud.ServerStatusOff}, nil, nil) - out, _, err := fx.Run(cmd, []string{server.Name, "--wait"}) + out, _, err := fx.Run(cmd, []string{srv.Name, "--wait"}) expOut := "Sent shutdown signal to server 42\nServer 42 shut down\n" diff --git a/internal/cmd/server/update_test.go b/internal/cmd/server/update_test.go index 82595e4a..d64ae3e9 100644 --- a/internal/cmd/server/update_test.go +++ b/internal/cmd/server/update_test.go @@ -1,4 +1,4 @@ -package server +package server_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := server.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerClient.EXPECT(). diff --git a/internal/cmd/servertype/describe_test.go b/internal/cmd/servertype/describe_test.go index d9565f3a..68b19af3 100644 --- a/internal/cmd/servertype/describe_test.go +++ b/internal/cmd/servertype/describe_test.go @@ -1,4 +1,4 @@ -package servertype +package servertype_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/servertype" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDescribe(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := servertype.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerTypeClient.EXPECT(). diff --git a/internal/cmd/servertype/list_test.go b/internal/cmd/servertype/list_test.go index f16128a4..2ed3b9a8 100644 --- a/internal/cmd/servertype/list_test.go +++ b/internal/cmd/servertype/list_test.go @@ -1,4 +1,4 @@ -package servertype +package servertype_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/servertype" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -18,7 +19,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := servertype.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.ServerTypeClient.EXPECT(). diff --git a/internal/cmd/sshkey/create_test.go b/internal/cmd/sshkey/create_test.go index e22b2c36..e2f3bb80 100644 --- a/internal/cmd/sshkey/create_test.go +++ b/internal/cmd/sshkey/create_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( _ "embed" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -19,7 +20,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := sshkey.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). @@ -48,7 +49,7 @@ func TestCreateJSON(t *testing.T) { time.Local = time.UTC - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := sshkey.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). diff --git a/internal/cmd/sshkey/delete_test.go b/internal/cmd/sshkey/delete_test.go index f6f47379..14640a11 100644 --- a/internal/cmd/sshkey/delete_test.go +++ b/internal/cmd/sshkey/delete_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := sshkey.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() sshKey := &hcloud.SSHKey{ diff --git a/internal/cmd/sshkey/describe_test.go b/internal/cmd/sshkey/describe_test.go index 8b6008b1..8e083b51 100644 --- a/internal/cmd/sshkey/describe_test.go +++ b/internal/cmd/sshkey/describe_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -20,7 +21,7 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := sshkey.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() key := &hcloud.SSHKey{ diff --git a/internal/cmd/sshkey/labels_test.go b/internal/cmd/sshkey/labels_test.go index d293ee6f..3b5d388b 100644 --- a/internal/cmd/sshkey/labels_test.go +++ b/internal/cmd/sshkey/labels_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := sshkey.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := sshkey.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). diff --git a/internal/cmd/sshkey/list_test.go b/internal/cmd/sshkey/list_test.go index 8e18e44d..1e9a94f5 100644 --- a/internal/cmd/sshkey/list_test.go +++ b/internal/cmd/sshkey/list_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := sshkey.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). diff --git a/internal/cmd/sshkey/update_test.go b/internal/cmd/sshkey/update_test.go index 0d516b66..155adaf9 100644 --- a/internal/cmd/sshkey/update_test.go +++ b/internal/cmd/sshkey/update_test.go @@ -1,4 +1,4 @@ -package sshkey +package sshkey_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := sshkey.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.SSHKeyClient.EXPECT(). diff --git a/internal/cmd/volume/create_test.go b/internal/cmd/volume/create_test.go index 2a45093d..c98c7889 100644 --- a/internal/cmd/volume/create_test.go +++ b/internal/cmd/volume/create_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( _ "embed" @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -19,7 +20,7 @@ func TestCreate(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := volume.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT(). @@ -58,7 +59,7 @@ func TestCreateJSON(t *testing.T) { time.Local = time.UTC - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := volume.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT(). @@ -103,10 +104,10 @@ func TestCreateProtection(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := CreateCmd.CobraCommand(fx.State()) + cmd := volume.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - volume := &hcloud.Volume{ + v := &hcloud.Volume{ ID: 123, Name: "test", Size: 20, @@ -121,7 +122,7 @@ func TestCreateProtection(t *testing.T) { Labels: make(map[string]string), }). Return(hcloud.VolumeCreateResult{ - Volume: volume, + Volume: v, Action: &hcloud.Action{ID: 321}, NextActions: []*hcloud.Action{{ID: 1}, {ID: 2}, {ID: 3}}, }, nil, nil) @@ -130,7 +131,7 @@ func TestCreateProtection(t *testing.T) { fx.ActionWaiter.EXPECT(). WaitForActions(gomock.Any(), gomock.Any(), []*hcloud.Action{{ID: 1}, {ID: 2}, {ID: 3}}) fx.Client.VolumeClient.EXPECT(). - ChangeProtection(gomock.Any(), volume, hcloud.VolumeChangeProtectionOpts{ + ChangeProtection(gomock.Any(), v, hcloud.VolumeChangeProtectionOpts{ Delete: hcloud.Ptr(true), }). Return(&hcloud.Action{ID: 123}, nil, nil) diff --git a/internal/cmd/volume/delete_test.go b/internal/cmd/volume/delete_test.go index a4ce604d..5f7613a9 100644 --- a/internal/cmd/volume/delete_test.go +++ b/internal/cmd/volume/delete_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,19 +15,19 @@ func TestDelete(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := DeleteCmd.CobraCommand(fx.State()) + cmd := volume.DeleteCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - volume := &hcloud.Volume{ + v := &hcloud.Volume{ ID: 123, Name: "test", } fx.Client.VolumeClient.EXPECT(). Get(gomock.Any(), "test"). - Return(volume, nil, nil) + Return(v, nil, nil) fx.Client.VolumeClient.EXPECT(). - Delete(gomock.Any(), volume). + Delete(gomock.Any(), v). Return(nil, nil) out, _, err := fx.Run(cmd, []string{"test"}) diff --git a/internal/cmd/volume/describe_test.go b/internal/cmd/volume/describe_test.go index abf09aa5..94124fd2 100644 --- a/internal/cmd/volume/describe_test.go +++ b/internal/cmd/volume/describe_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( "fmt" @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/hetznercloud/cli/internal/cmd/util" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -20,10 +21,10 @@ func TestDescribe(t *testing.T) { time.Local = time.UTC - cmd := DescribeCmd.CobraCommand(fx.State()) + cmd := volume.DescribeCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() - volume := &hcloud.Volume{ + v := &hcloud.Volume{ ID: 123, Name: "test", Size: 50, @@ -43,7 +44,7 @@ func TestDescribe(t *testing.T) { fx.Client.VolumeClient.EXPECT(). Get(gomock.Any(), "test"). - Return(volume, nil, nil) + Return(v, nil, nil) fx.Client.ServerClient.EXPECT(). ServerName(int64(321)). Return("myServer") @@ -69,7 +70,7 @@ Protection: Delete: no Labels: No labels -`, util.Datetime(volume.Created), humanize.Time(volume.Created)) +`, util.Datetime(v.Created), humanize.Time(v.Created)) assert.NoError(t, err) assert.Equal(t, expOut, out) diff --git a/internal/cmd/volume/labels_test.go b/internal/cmd/volume/labels_test.go index 6bc15220..fe8cb952 100644 --- a/internal/cmd/volume/labels_test.go +++ b/internal/cmd/volume/labels_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.AddCobraCommand(fx.State()) + cmd := volume.LabelCmds.AddCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT(). @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := LabelCmds.RemoveCobraCommand(fx.State()) + cmd := volume.LabelCmds.RemoveCobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT(). diff --git a/internal/cmd/volume/list_test.go b/internal/cmd/volume/list_test.go index d932a82f..5fda734f 100644 --- a/internal/cmd/volume/list_test.go +++ b/internal/cmd/volume/list_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( "testing" @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -17,7 +18,7 @@ func TestList(t *testing.T) { time.Local = time.UTC - cmd := ListCmd.CobraCommand(fx.State()) + cmd := volume.ListCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT(). diff --git a/internal/cmd/volume/update_test.go b/internal/cmd/volume/update_test.go index 9117e27a..2e65b6a3 100644 --- a/internal/cmd/volume/update_test.go +++ b/internal/cmd/volume/update_test.go @@ -1,4 +1,4 @@ -package volume +package volume_test import ( "testing" @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) { fx := testutil.NewFixture(t) defer fx.Finish() - cmd := UpdateCmd.CobraCommand(fx.State()) + cmd := volume.UpdateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() fx.Client.VolumeClient.EXPECT().