github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/volume_status_test.go (about)

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