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