github.com/ThomasObenaus/nomad@v0.11.1/command/volume_status_test.go (about) 1 package command 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/helper/uuid" 7 "github.com/hashicorp/nomad/nomad/structs" 8 "github.com/mitchellh/cli" 9 "github.com/posener/complete" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestCSIVolumeStatusCommand_Implements(t *testing.T) { 14 t.Parallel() 15 var _ cli.Command = &VolumeStatusCommand{} 16 } 17 18 func TestCSIVolumeStatusCommand_Fails(t *testing.T) { 19 t.Parallel() 20 ui := new(cli.MockUi) 21 cmd := &VolumeStatusCommand{Meta: Meta{Ui: ui}} 22 23 // Fails on misuse 24 code := cmd.Run([]string{"some", "bad", "args"}) 25 require.Equal(t, 1, code) 26 27 out := ui.ErrorWriter.String() 28 require.Contains(t, out, commandErrorText(cmd)) 29 ui.ErrorWriter.Reset() 30 } 31 32 func TestCSIVolumeStatusCommand_AutocompleteArgs(t *testing.T) { 33 t.Parallel() 34 35 srv, _, url := testServer(t, true, nil) 36 defer srv.Shutdown() 37 38 ui := new(cli.MockUi) 39 cmd := &VolumeStatusCommand{Meta: Meta{Ui: ui, flagAddress: url}} 40 41 state := srv.Agent.Server().State() 42 43 vol := &structs.CSIVolume{ 44 ID: uuid.Generate(), 45 Namespace: "default", 46 PluginID: "glade", 47 } 48 49 require.NoError(t, state.CSIVolumeRegister(1000, []*structs.CSIVolume{vol})) 50 51 prefix := vol.ID[:len(vol.ID)-5] 52 args := complete.Args{Last: prefix} 53 predictor := cmd.AutocompleteArgs() 54 55 res := predictor.Predict(args) 56 require.Equal(t, 1, len(res)) 57 require.Equal(t, vol.ID, res[0]) 58 }