github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/deployment_unblock_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/nomad/ci" 8 "github.com/hashicorp/nomad/nomad/mock" 9 "github.com/mitchellh/cli" 10 "github.com/posener/complete" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestDeploymentUnblockCommand_Implements(t *testing.T) { 15 ci.Parallel(t) 16 var _ cli.Command = &DeploymentUnblockCommand{} 17 } 18 19 func TestDeploymentUnblockCommand_Fails(t *testing.T) { 20 ci.Parallel(t) 21 ui := cli.NewMockUi() 22 cmd := &DeploymentUnblockCommand{Meta: Meta{Ui: ui}} 23 24 // Unblocks on misuse 25 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 26 t.Fatalf("expected exit code 1, got: %d", code) 27 } 28 if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { 29 t.Fatalf("expected help output, got: %s", out) 30 } 31 ui.ErrorWriter.Reset() 32 33 if code := cmd.Run([]string{"-address=nope", "12"}); code != 1 { 34 t.Fatalf("expected exit code 1, got: %d", code) 35 } 36 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error retrieving deployment") { 37 t.Fatalf("expected unblocked query error, got: %s", out) 38 } 39 ui.ErrorWriter.Reset() 40 } 41 42 func TestDeploymentUnblockCommand_AutocompleteArgs(t *testing.T) { 43 ci.Parallel(t) 44 assert := assert.New(t) 45 46 srv, _, url := testServer(t, true, nil) 47 defer srv.Shutdown() 48 49 ui := cli.NewMockUi() 50 cmd := &DeploymentUnblockCommand{Meta: Meta{Ui: ui, flagAddress: url}} 51 52 // Create a fake deployment 53 state := srv.Agent.Server().State() 54 d := mock.Deployment() 55 assert.Nil(state.UpsertDeployment(1000, d)) 56 57 prefix := d.ID[:5] 58 args := complete.Args{Last: prefix} 59 predictor := cmd.AutocompleteArgs() 60 61 res := predictor.Predict(args) 62 assert.Equal(1, len(res)) 63 assert.Equal(d.ID, res[0]) 64 }