diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd48d50a..74050f0f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ - refactor(argparser/flags.go): add flag conversion utilities for converting string flags to bools and checking ascending and desecnding flags ([#1611](https://github.com/fastly/cli/pull/1611)) - feat(service/purge): Add 'service purge' command as replacement for 'purge', with an unlisted and deprecated alias of 'purge'. ([#1612](https://github.com/fastly/cli/pull/1612)) - feat(service/version): Add 'service version ...' commands as replacements for 'service-version ...', with unlisted and deprecated aliases of 'service-version ...'. ([#1614](https://github.com/fastly/cli/pull/1614)) -- feat(vcl): moved the `vcl` command under the `service` command, with an unlisted and deprecated alias of `vcl` ([#1616](https://github.com/fastly/cli/pull/1616)) +- feat(service/vcl): moved the `vcl` command under the `service` command, with an unlisted and deprecated alias of `vcl` ([#1616](https://github.com/fastly/cli/pull/1616)) +- feat(service/healthcheck): moved the `healthcheck` command under the `service` command, with an unlisted and deprecated alias of `healthcheck` ([#1619](https://github.com/fastly/cli/pull/1619)) ### Bug fixes: diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index ac7ad2d34..921c3d967 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -73,7 +73,6 @@ dashboard dictionary dictionary-entry domain -healthcheck imageoptimizer install ip-list diff --git a/pkg/commands/alias/healthcheck/create.go b/pkg/commands/alias/healthcheck/create.go new file mode 100644 index 000000000..c43ff1b41 --- /dev/null +++ b/pkg/commands/alias/healthcheck/create.go @@ -0,0 +1,29 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// CreateCommand wraps the CreateCommand from the servicehealthcheck package. +type CreateCommand struct { + *servicehealthcheck.CreateCommand +} + +// NewCreateCommand returns a usable command registered under the parent. +func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand { + c := CreateCommand{servicehealthcheck.NewCreateCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service healthcheck create' command instead.") + return c.CreateCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/healthcheck/delete.go b/pkg/commands/alias/healthcheck/delete.go new file mode 100644 index 000000000..1b712672e --- /dev/null +++ b/pkg/commands/alias/healthcheck/delete.go @@ -0,0 +1,29 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// DeleteCommand wraps the DeleteCommand from the servicehealthcheck package. +type DeleteCommand struct { + *servicehealthcheck.DeleteCommand +} + +// NewDeleteCommand returns a usable command registered under the parent. +func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand { + c := DeleteCommand{servicehealthcheck.NewDeleteCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service healthcheck delete' command instead.") + return c.DeleteCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/healthcheck/describe.go b/pkg/commands/alias/healthcheck/describe.go new file mode 100644 index 000000000..422bd71e0 --- /dev/null +++ b/pkg/commands/alias/healthcheck/describe.go @@ -0,0 +1,29 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// DescribeCommand wraps the DescribeCommand from the servicehealthcheck package. +type DescribeCommand struct { + *servicehealthcheck.DescribeCommand +} + +// NewDescribeCommand returns a usable command registered under the parent. +func NewDescribeCommand(parent argparser.Registerer, g *global.Data) *DescribeCommand { + c := DescribeCommand{servicehealthcheck.NewDescribeCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service healthcheck describe' command instead.") + return c.DescribeCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/healthcheck/doc.go b/pkg/commands/alias/healthcheck/doc.go new file mode 100644 index 000000000..ca3e62724 --- /dev/null +++ b/pkg/commands/alias/healthcheck/doc.go @@ -0,0 +1,2 @@ +// Package healthcheck contains the 'healthcheck' alias for the 'service healthcheck' command. +package healthcheck diff --git a/pkg/commands/alias/healthcheck/list.go b/pkg/commands/alias/healthcheck/list.go new file mode 100644 index 000000000..2310e1c90 --- /dev/null +++ b/pkg/commands/alias/healthcheck/list.go @@ -0,0 +1,29 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// ListCommand wraps the ListCommand from the servicehealthcheck package. +type ListCommand struct { + *servicehealthcheck.ListCommand +} + +// NewListCommand returns a usable command registered under the parent. +func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand { + c := ListCommand{servicehealthcheck.NewListCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *ListCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service healthcheck list' command instead.") + return c.ListCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/healthcheck/root.go b/pkg/commands/alias/healthcheck/root.go new file mode 100644 index 000000000..8fa2cbe3e --- /dev/null +++ b/pkg/commands/alias/healthcheck/root.go @@ -0,0 +1,27 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" +) + +// RootCommand wraps the RootCommand from the servicehealthcheck package. +type RootCommand struct { + *servicehealthcheck.RootCommand +} + +// NewRootCommand returns a usable command registered under the parent. +func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand { + c := RootCommand{servicehealthcheck.NewRootCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { + return c.RootCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/healthcheck/update.go b/pkg/commands/alias/healthcheck/update.go new file mode 100644 index 000000000..e0f8702b6 --- /dev/null +++ b/pkg/commands/alias/healthcheck/update.go @@ -0,0 +1,29 @@ +package healthcheck + +import ( + "io" + + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// UpdateCommand wraps the UpdateCommand from the servicehealthcheck package. +type UpdateCommand struct { + *servicehealthcheck.UpdateCommand +} + +// NewUpdateCommand returns a usable command registered under the parent. +func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateCommand { + c := UpdateCommand{servicehealthcheck.NewUpdateCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service healthcheck update' command instead.") + return c.UpdateCommand.Exec(in, out) +} diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index c0fc6ba1c..47a7dc98e 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -7,6 +7,7 @@ import ( "github.com/fastly/cli/pkg/commands/acl" "github.com/fastly/cli/pkg/commands/aclentry" "github.com/fastly/cli/pkg/commands/alerts" + aliashealthcheck "github.com/fastly/cli/pkg/commands/alias/healthcheck" aliaspurge "github.com/fastly/cli/pkg/commands/alias/purge" aliasvcl "github.com/fastly/cli/pkg/commands/alias/vcl" aliasvclcondition "github.com/fastly/cli/pkg/commands/alias/vcl/condition" @@ -25,7 +26,6 @@ import ( "github.com/fastly/cli/pkg/commands/dictionary" "github.com/fastly/cli/pkg/commands/dictionaryentry" "github.com/fastly/cli/pkg/commands/domain" - "github.com/fastly/cli/pkg/commands/healthcheck" "github.com/fastly/cli/pkg/commands/imageoptimizerdefaults" "github.com/fastly/cli/pkg/commands/install" "github.com/fastly/cli/pkg/commands/ip" @@ -99,6 +99,7 @@ import ( "github.com/fastly/cli/pkg/commands/secretstoreentry" "github.com/fastly/cli/pkg/commands/service" servicedomain "github.com/fastly/cli/pkg/commands/service/domain" + servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck" servicepurge "github.com/fastly/cli/pkg/commands/service/purge" servicevcl "github.com/fastly/cli/pkg/commands/service/vcl" servicevclcondition "github.com/fastly/cli/pkg/commands/service/vcl/condition" @@ -233,12 +234,12 @@ func Define( // nolint:revive // function-length domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, data) domainList := domain.NewListCommand(domainCmdRoot.CmdClause, data) domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, data) - healthcheckCmdRoot := healthcheck.NewRootCommand(app, data) - healthcheckCreate := healthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, data) - healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, data) - healthcheckDescribe := healthcheck.NewDescribeCommand(healthcheckCmdRoot.CmdClause, data) - healthcheckList := healthcheck.NewListCommand(healthcheckCmdRoot.CmdClause, data) - healthcheckUpdate := healthcheck.NewUpdateCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckCmdRoot := aliashealthcheck.NewRootCommand(app, data) + healthcheckCreate := aliashealthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckDelete := aliashealthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckDescribe := aliashealthcheck.NewDescribeCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckList := aliashealthcheck.NewListCommand(healthcheckCmdRoot.CmdClause, data) + healthcheckUpdate := aliashealthcheck.NewUpdateCommand(healthcheckCmdRoot.CmdClause, data) imageoptimizerdefaultsCmdRoot := imageoptimizerdefaults.NewRootCommand(app, data) imageoptimizerdefaultsGet := imageoptimizerdefaults.NewGetCommand(imageoptimizerdefaultsCmdRoot.CmdClause, data) imageoptimizerdefaultsUpdate := imageoptimizerdefaults.NewUpdateCommand(imageoptimizerdefaultsCmdRoot.CmdClause, data) @@ -664,6 +665,12 @@ func Define( // nolint:revive // function-length servicedomainList := servicedomain.NewListCommand(servicedomainCmdRoot.CmdClause, data) servicedomainUpdate := servicedomain.NewUpdateCommand(servicedomainCmdRoot.CmdClause, data) servicedomainValidate := servicedomain.NewValidateCommand(servicedomainCmdRoot.CmdClause, data) + servicehealthcheckCmdRoot := servicehealthcheck.NewRootCommand(serviceCmdRoot.CmdClause, data) + servicehealthcheckCreate := servicehealthcheck.NewCreateCommand(servicehealthcheckCmdRoot.CmdClause, data) + servicehealthcheckDelete := servicehealthcheck.NewDeleteCommand(servicehealthcheckCmdRoot.CmdClause, data) + servicehealthcheckDescribe := servicehealthcheck.NewDescribeCommand(servicehealthcheckCmdRoot.CmdClause, data) + servicehealthcheckList := servicehealthcheck.NewListCommand(servicehealthcheckCmdRoot.CmdClause, data) + servicehealthcheckUpdate := servicehealthcheck.NewUpdateCommand(servicehealthcheckCmdRoot.CmdClause, data) statsCmdRoot := stats.NewRootCommand(app, data) statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, data) statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, data) @@ -843,7 +850,6 @@ func Define( // nolint:revive // function-length domainDescribe, domainList, domainUpdate, - healthcheckCmdRoot, healthcheckCreate, healthcheckDelete, healthcheckDescribe, @@ -1259,6 +1265,12 @@ func Define( // nolint:revive // function-length servicedomainList, servicedomainUpdate, servicedomainValidate, + servicehealthcheckCmdRoot, + servicehealthcheckCreate, + servicehealthcheckDelete, + servicehealthcheckDescribe, + servicehealthcheckList, + servicehealthcheckUpdate, serviceVersionActivate, serviceVersionClone, serviceVersionCmdRoot, diff --git a/pkg/commands/healthcheck/create.go b/pkg/commands/service/healthcheck/create.go similarity index 100% rename from pkg/commands/healthcheck/create.go rename to pkg/commands/service/healthcheck/create.go diff --git a/pkg/commands/healthcheck/delete.go b/pkg/commands/service/healthcheck/delete.go similarity index 100% rename from pkg/commands/healthcheck/delete.go rename to pkg/commands/service/healthcheck/delete.go diff --git a/pkg/commands/healthcheck/describe.go b/pkg/commands/service/healthcheck/describe.go similarity index 100% rename from pkg/commands/healthcheck/describe.go rename to pkg/commands/service/healthcheck/describe.go diff --git a/pkg/commands/healthcheck/doc.go b/pkg/commands/service/healthcheck/doc.go similarity index 100% rename from pkg/commands/healthcheck/doc.go rename to pkg/commands/service/healthcheck/doc.go diff --git a/pkg/commands/healthcheck/healthcheck_test.go b/pkg/commands/service/healthcheck/healthcheck_test.go similarity index 51% rename from pkg/commands/healthcheck/healthcheck_test.go rename to pkg/commands/service/healthcheck/healthcheck_test.go index ff10f137d..f1fed7e13 100644 --- a/pkg/commands/healthcheck/healthcheck_test.go +++ b/pkg/commands/service/healthcheck/healthcheck_test.go @@ -1,289 +1,192 @@ package healthcheck_test import ( - "bytes" "context" "errors" - "io" "net/http" "strings" "testing" + root "github.com/fastly/cli/pkg/commands/service" + sub "github.com/fastly/cli/pkg/commands/service/healthcheck" "github.com/fastly/go-fastly/v12/fastly" - "github.com/fastly/cli/pkg/app" - "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) func TestHealthCheckCreate(t *testing.T) { - args := testutil.SplitArgs - scenarios := []struct { - args []string - api mock.API - wantError string - wantOutput string - }{ + scenarios := []testutil.CLIScenario{ { - args: args("healthcheck create --version 1"), - wantError: "error reading service: no service ID found", + Args: "--version 1", + WantError: "error reading service: no service ID found", }, { - args: args("healthcheck create --service-id 123 --version 1 --name www.test.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), CreateHealthCheckFn: createHealthCheckError, }, - wantError: errTest.Error(), + WantError: errTest.Error(), }, // NOTE: Added --timeout flag to validate that a nil pointer dereference is // not triggered at runtime when parsing the arguments. { - args: args("healthcheck create --service-id 123 --version 1 --name www.test.com --autoclone --timeout 10"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --autoclone --timeout 10", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), CreateHealthCheckFn: createHealthCheckOK, }, - wantOutput: "Created healthcheck www.test.com (service 123 version 4)", + WantOutput: "Created healthcheck www.test.com (service 123 version 4)", }, } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { - var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.APIClientFactory = mock.APIClient(testcase.api) - return opts, nil - } - err := app.Run(testcase.args, nil) - testutil.AssertErrorContains(t, err, testcase.wantError) - testutil.AssertStringContains(t, stdout.String(), testcase.wantOutput) - }) - } + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "create"}, scenarios) } func TestHealthCheckList(t *testing.T) { - args := testutil.SplitArgs - scenarios := []struct { - args []string - api mock.API - wantError string - wantOutput string - }{ + scenarios := []testutil.CLIScenario{ { - args: args("healthcheck list --service-id 123 --version 1"), - api: mock.API{ + Args: "--service-id 123 --version 1", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksOK, }, - wantOutput: listHealthChecksShortOutput, + WantOutput: listHealthChecksShortOutput, }, { - args: args("healthcheck list --service-id 123 --version 1 --verbose"), - api: mock.API{ + Args: "--service-id 123 --version 1 --verbose", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksOK, }, - wantOutput: listHealthChecksVerboseOutput, + WantOutput: listHealthChecksVerboseOutput, }, { - args: args("healthcheck list --service-id 123 --version 1 -v"), - api: mock.API{ + Args: "--service-id 123 --version 1 -v", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksOK, }, - wantOutput: listHealthChecksVerboseOutput, + WantOutput: listHealthChecksVerboseOutput, }, { - args: args("healthcheck --verbose list --service-id 123 --version 1"), - api: mock.API{ + Args: "--verbose --service-id 123 --version 1", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksOK, }, - wantOutput: listHealthChecksVerboseOutput, + WantOutput: listHealthChecksVerboseOutput, }, { - args: args("-v healthcheck list --service-id 123 --version 1"), - api: mock.API{ + Args: "-v --service-id 123 --version 1", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksOK, }, - wantOutput: listHealthChecksVerboseOutput, + WantOutput: listHealthChecksVerboseOutput, }, { - args: args("healthcheck list --service-id 123 --version 1"), - api: mock.API{ + Args: "--service-id 123 --version 1", + API: mock.API{ ListVersionsFn: testutil.ListVersions, ListHealthChecksFn: listHealthChecksError, }, - wantError: errTest.Error(), + WantError: errTest.Error(), }, } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { - var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.APIClientFactory = mock.APIClient(testcase.api) - return opts, nil - } - err := app.Run(testcase.args, nil) - testutil.AssertErrorContains(t, err, testcase.wantError) - testutil.AssertString(t, testcase.wantOutput, stdout.String()) - }) - } + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "list"}, scenarios) } func TestHealthCheckDescribe(t *testing.T) { - args := testutil.SplitArgs - scenarios := []struct { - args []string - api mock.API - wantError string - wantOutput string - }{ + scenarios := []testutil.CLIScenario{ { - args: args("healthcheck describe --service-id 123 --version 1"), - wantError: "error parsing arguments: required flag --name not provided", + Args: "--service-id 123 --version 1", + WantError: "error parsing arguments: required flag --name not provided", }, { - args: args("healthcheck describe --service-id 123 --version 1 --name www.test.com"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com", + API: mock.API{ ListVersionsFn: testutil.ListVersions, GetHealthCheckFn: getHealthCheckError, }, - wantError: errTest.Error(), + WantError: errTest.Error(), }, { - args: args("healthcheck describe --service-id 123 --version 1 --name www.test.com"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com", + API: mock.API{ ListVersionsFn: testutil.ListVersions, GetHealthCheckFn: getHealthCheckOK, }, - wantOutput: describeHealthCheckOutput, + WantOutput: describeHealthCheckOutput, }, } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { - var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.APIClientFactory = mock.APIClient(testcase.api) - return opts, nil - } - err := app.Run(testcase.args, nil) - testutil.AssertErrorContains(t, err, testcase.wantError) - testutil.AssertString(t, testcase.wantOutput, stdout.String()) - }) - } + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "describe"}, scenarios) } func TestHealthCheckUpdate(t *testing.T) { - args := testutil.SplitArgs - scenarios := []struct { - args []string - api mock.API - wantError string - wantOutput string - }{ + scenarios := []testutil.CLIScenario{ { - args: args("healthcheck update --service-id 123 --version 1 --new-name www.test.com --comment "), - wantError: "error parsing arguments: required flag --name not provided", + Args: "--service-id 123 --version 1 --new-name www.test.com --comment ", + WantError: "error parsing arguments: required flag --name not provided", }, { - args: args("healthcheck update --service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), UpdateHealthCheckFn: updateHealthCheckOK, }, }, { - args: args("healthcheck update --service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), UpdateHealthCheckFn: updateHealthCheckError, }, - wantError: errTest.Error(), + WantError: errTest.Error(), }, { - args: args("healthcheck update --service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --new-name www.example.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), UpdateHealthCheckFn: updateHealthCheckOK, }, - wantOutput: "Updated healthcheck www.example.com (service 123 version 4)", + WantOutput: "Updated healthcheck www.example.com (service 123 version 4)", }, } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { - var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.APIClientFactory = mock.APIClient(testcase.api) - return opts, nil - } - err := app.Run(testcase.args, nil) - testutil.AssertErrorContains(t, err, testcase.wantError) - testutil.AssertStringContains(t, stdout.String(), testcase.wantOutput) - }) - } + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "update"}, scenarios) } func TestHealthCheckDelete(t *testing.T) { - args := testutil.SplitArgs - scenarios := []struct { - args []string - api mock.API - wantError string - wantOutput string - }{ + scenarios := []testutil.CLIScenario{ { - args: args("healthcheck delete --service-id 123 --version 1"), - wantError: "error parsing arguments: required flag --name not provided", + Args: ("--service-id 123 --version 1"), + WantError: "error parsing arguments: required flag --name not provided", }, { - args: args("healthcheck delete --service-id 123 --version 1 --name www.test.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), DeleteHealthCheckFn: deleteHealthCheckError, }, - wantError: errTest.Error(), + WantError: errTest.Error(), }, { - args: args("healthcheck delete --service-id 123 --version 1 --name www.test.com --autoclone"), - api: mock.API{ + Args: "--service-id 123 --version 1 --name www.test.com --autoclone", + API: mock.API{ ListVersionsFn: testutil.ListVersions, CloneVersionFn: testutil.CloneVersionResult(4), DeleteHealthCheckFn: deleteHealthCheckOK, }, - wantOutput: "Deleted healthcheck www.test.com (service 123 version 4)", + WantOutput: "Deleted healthcheck www.test.com (service 123 version 4)", }, } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { - var stdout bytes.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.APIClientFactory = mock.APIClient(testcase.api) - return opts, nil - } - err := app.Run(testcase.args, nil) - testutil.AssertErrorContains(t, err, testcase.wantError) - testutil.AssertStringContains(t, stdout.String(), testcase.wantOutput) - }) - } + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "delete"}, scenarios) } var errTest = errors.New("fixture error") diff --git a/pkg/commands/healthcheck/list.go b/pkg/commands/service/healthcheck/list.go similarity index 100% rename from pkg/commands/healthcheck/list.go rename to pkg/commands/service/healthcheck/list.go diff --git a/pkg/commands/healthcheck/root.go b/pkg/commands/service/healthcheck/root.go similarity index 100% rename from pkg/commands/healthcheck/root.go rename to pkg/commands/service/healthcheck/root.go diff --git a/pkg/commands/healthcheck/update.go b/pkg/commands/service/healthcheck/update.go similarity index 100% rename from pkg/commands/healthcheck/update.go rename to pkg/commands/service/healthcheck/update.go