2017-02-27 12:39:35 -05:00
|
|
|
package volume
|
|
|
|
|
|
|
|
import (
|
2022-02-25 08:34:38 -05:00
|
|
|
"io"
|
2017-02-27 12:39:35 -05:00
|
|
|
"testing"
|
|
|
|
|
2017-08-21 16:30:09 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2017-02-27 12:39:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVolumeRemoveErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
|
|
|
volumeRemoveFunc func(volumeID string, force bool) error
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
expectedError: "requires at least 1 argument",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"nodeID"},
|
|
|
|
volumeRemoveFunc: func(volumeID string, force bool) error {
|
2017-03-09 13:23:45 -05:00
|
|
|
return errors.Errorf("error removing the volume")
|
2017-02-27 12:39:35 -05:00
|
|
|
},
|
|
|
|
expectedError: "error removing the volume",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
cmd := newRemoveCommand(
|
2017-08-16 13:50:28 -04:00
|
|
|
test.NewFakeCli(&fakeClient{
|
2017-02-27 12:39:35 -05:00
|
|
|
volumeRemoveFunc: tc.volumeRemoveFunc,
|
2017-08-16 13:50:28 -04:00
|
|
|
}))
|
2017-02-27 12:39:35 -05:00
|
|
|
cmd.SetArgs(tc.args)
|
2022-02-25 08:34:38 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2023-02-07 20:27:51 -05:00
|
|
|
cmd.SetErr(io.Discard)
|
2018-03-06 14:03:47 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2017-02-27 12:39:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeRemoveMultiple(t *testing.T) {
|
2017-08-16 13:50:28 -04:00
|
|
|
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
|
2017-02-27 12:39:35 -05:00
|
|
|
cmd.SetArgs([]string{"volume1", "volume2"})
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2017-02-27 12:39:35 -05:00
|
|
|
}
|