github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/command/volume/remove_test.go (about)

     1  package volume
     2  
     3  import (
     4  	"io/ioutil"
     5  	"testing"
     6  
     7  	"github.com/docker/cli/internal/test"
     8  	"github.com/pkg/errors"
     9  	"gotest.tools/v3/assert"
    10  )
    11  
    12  func TestVolumeRemoveErrors(t *testing.T) {
    13  	testCases := []struct {
    14  		args             []string
    15  		volumeRemoveFunc func(volumeID string, force bool) error
    16  		expectedError    string
    17  	}{
    18  		{
    19  			expectedError: "requires at least 1 argument",
    20  		},
    21  		{
    22  			args: []string{"nodeID"},
    23  			volumeRemoveFunc: func(volumeID string, force bool) error {
    24  				return errors.Errorf("error removing the volume")
    25  			},
    26  			expectedError: "error removing the volume",
    27  		},
    28  	}
    29  	for _, tc := range testCases {
    30  		cmd := newRemoveCommand(
    31  			test.NewFakeCli(&fakeClient{
    32  				volumeRemoveFunc: tc.volumeRemoveFunc,
    33  			}))
    34  		cmd.SetArgs(tc.args)
    35  		cmd.SetOut(ioutil.Discard)
    36  		assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
    37  	}
    38  }
    39  
    40  func TestNodeRemoveMultiple(t *testing.T) {
    41  	cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
    42  	cmd.SetArgs([]string{"volume1", "volume2"})
    43  	assert.NilError(t, cmd.Execute())
    44  }