github.com/hernad/nomad@v1.6.112/command/volume_status_test.go (about)

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