diff --git a/command/commands.go b/command/commands.go index efcd86ccc..8504e4dbc 100644 --- a/command/commands.go +++ b/command/commands.go @@ -655,17 +655,23 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory { }, "recommendation apply": func() (cli.Command, error) { return &RecommendationApplyCommand{ - Meta: meta, + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: meta, + }, }, nil }, "recommendation dismiss": func() (cli.Command, error) { return &RecommendationDismissCommand{ - Meta: meta, + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: meta, + }, }, nil }, "recommendation info": func() (cli.Command, error) { return &RecommendationInfoCommand{ - Meta: meta, + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: meta, + }, }, nil }, "recommendation list": func() (cli.Command, error) { diff --git a/command/recommendation_apply.go b/command/recommendation_apply.go index 6482013e4..0e394c2a7 100644 --- a/command/recommendation_apply.go +++ b/command/recommendation_apply.go @@ -15,7 +15,6 @@ var _ cli.Command = &RecommendationApplyCommand{} // RecommendationApplyCommand implements cli.Command. type RecommendationApplyCommand struct { - Meta RecommendationAutocompleteCommand } diff --git a/command/recommendation_apply_test.go b/command/recommendation_apply_test.go index b2f051ff1..e3538b6b2 100644 --- a/command/recommendation_apply_test.go +++ b/command/recommendation_apply_test.go @@ -33,7 +33,13 @@ func TestRecommendationApplyCommand_Run(t *testing.T) { }) ui := cli.NewMockUi() - cmd := &RecommendationApplyCommand{Meta: Meta{Ui: ui}} + cmd := &RecommendationApplyCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{ + Ui: ui, + }, + }, + } // Register a test job to write a recommendation against. testJob := testJob("recommendation_apply") @@ -86,10 +92,17 @@ func TestRecommendationApplyCommand_Run(t *testing.T) { } func TestRecommendationApplyCommand_AutocompleteArgs(t *testing.T) { - srv, client, url := testServer(t, true, nil) + srv, client, url := testServer(t, false, nil) defer srv.Shutdown() ui := cli.NewMockUi() - cmd := RecommendationApplyCommand{Meta: Meta{Ui: ui, flagAddress: url}} - testRecommendationAutocompleteCommand(t, client, srv, ui, &cmd.RecommendationAutocompleteCommand) + cmd := RecommendationApplyCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{ + Ui: ui, + flagAddress: url, + }, + }, + } + testRecommendationAutocompleteCommand(t, client, srv, &cmd.RecommendationAutocompleteCommand) } diff --git a/command/recommendation_dismiss.go b/command/recommendation_dismiss.go index 66bc9b626..00edfa8ef 100644 --- a/command/recommendation_dismiss.go +++ b/command/recommendation_dismiss.go @@ -36,7 +36,6 @@ func (r *RecommendationAutocompleteCommand) AutocompleteArgs() complete.Predicto // RecommendationDismissCommand implements cli.Command. type RecommendationDismissCommand struct { - Meta RecommendationAutocompleteCommand } diff --git a/command/recommendation_dismiss_test.go b/command/recommendation_dismiss_test.go index bcd106389..71553b7ae 100644 --- a/command/recommendation_dismiss_test.go +++ b/command/recommendation_dismiss_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" + "github.com/mitchellh/cli" + "github.com/posener/complete" + "github.com/stretchr/testify/require" + "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/command/agent" "github.com/hashicorp/nomad/testutil" - "github.com/mitchellh/cli" - "github.com/posener/complete" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestRecommendationDismissCommand_Run(t *testing.T) { @@ -35,7 +35,14 @@ func TestRecommendationDismissCommand_Run(t *testing.T) { }) ui := cli.NewMockUi() - cmd := &RecommendationDismissCommand{Meta: Meta{Ui: ui}} + cmd := &RecommendationDismissCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{ + Ui: ui, + flagAddress: url, + }, + }, + } // Register a test job to write a recommendation against. testJob := testJob("recommendation_dismiss") @@ -85,25 +92,30 @@ func TestRecommendationDismissCommand_Run(t *testing.T) { } func TestRecommendationDismissCommand_AutocompleteArgs(t *testing.T) { - srv, client, url := testServer(t, true, nil) + srv, client, url := testServer(t, false, nil) defer srv.Shutdown() ui := cli.NewMockUi() - cmd := &RecommendationDismissCommand{Meta: Meta{Ui: ui, flagAddress: url}} + cmd := &RecommendationDismissCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{ + Ui: ui, + flagAddress: url, + }, + }, + } - testRecommendationAutocompleteCommand(t, client, srv, ui, &cmd.RecommendationAutocompleteCommand) + testRecommendationAutocompleteCommand(t, client, srv, &cmd.RecommendationAutocompleteCommand) } -func testRecommendationAutocompleteCommand(t *testing.T, client *api.Client, srv *agent.TestAgent, ui *cli.MockUi, cmd *RecommendationAutocompleteCommand) { - assert := assert.New(t) +func testRecommendationAutocompleteCommand(t *testing.T, client *api.Client, srv *agent.TestAgent, cmd *RecommendationAutocompleteCommand) { + require := require.New(t) t.Parallel() // Register a test job to write a recommendation against. testJob := testJob("recommendation_autocomplete") - regResp, _, err := client.Jobs().Register(testJob, nil) - require.NoError(t, err) - registerCode := waitForSuccess(ui, client, fullId, t, regResp.EvalID) - require.Equal(t, 0, registerCode) + _, _, err := client.Jobs().Register(testJob, nil) + require.NoError(err) // Write a recommendation. rec := &api.Recommendation{ @@ -117,9 +129,9 @@ func testRecommendationAutocompleteCommand(t *testing.T, client *api.Client, srv } rec, _, err = client.Recommendations().Upsert(rec, nil) if srv.Enterprise { - require.NoError(t, err) + require.NoError(err) } else { - require.Error(t, err, "Nomad Enterprise only endpoint") + require.Error(err, "Nomad Enterprise only endpoint") return } @@ -128,6 +140,6 @@ func testRecommendationAutocompleteCommand(t *testing.T, client *api.Client, srv predictor := cmd.AutocompleteArgs() res := predictor.Predict(args) - assert.Equal(1, len(res)) - assert.Equal(rec.ID, res[0]) + require.Equal(1, len(res)) + require.Equal(rec.ID, res[0]) } diff --git a/command/recommendation_info.go b/command/recommendation_info.go index 2105f1b70..c009cba58 100644 --- a/command/recommendation_info.go +++ b/command/recommendation_info.go @@ -14,7 +14,6 @@ var _ cli.Command = &RecommendationInfoCommand{} // RecommendationInfoCommand implements cli.Command. type RecommendationInfoCommand struct { - Meta RecommendationAutocompleteCommand } diff --git a/command/recommendation_info_test.go b/command/recommendation_info_test.go index 29e564fe1..1e1a31864 100644 --- a/command/recommendation_info_test.go +++ b/command/recommendation_info_test.go @@ -33,7 +33,11 @@ func TestRecommendationInfoCommand_Run(t *testing.T) { }) ui := cli.NewMockUi() - cmd := &RecommendationInfoCommand{Meta: Meta{Ui: ui}} + cmd := &RecommendationInfoCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{Ui: ui}, + }, + } // Perform an initial call, which should return a not found error. code := cmd.Run([]string{"-address=" + url, "2c13f001-f5b6-ce36-03a5-e37afe160df5"}) @@ -84,10 +88,17 @@ func TestRecommendationInfoCommand_Run(t *testing.T) { } func TestRecommendationInfoCommand_AutocompleteArgs(t *testing.T) { - srv, client, url := testServer(t, true, nil) + srv, client, url := testServer(t, false, nil) defer srv.Shutdown() ui := cli.NewMockUi() - cmd := RecommendationInfoCommand{Meta: Meta{Ui: ui, flagAddress: url}} - testRecommendationAutocompleteCommand(t, client, srv, ui, &cmd.RecommendationAutocompleteCommand) + cmd := RecommendationInfoCommand{ + RecommendationAutocompleteCommand: RecommendationAutocompleteCommand{ + Meta: Meta{ + Ui: ui, + flagAddress: url, + }, + }, + } + testRecommendationAutocompleteCommand(t, client, srv, &cmd.RecommendationAutocompleteCommand) }