2017-02-27 12:39:35 -05:00
|
|
|
package volume
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli/internal/test"
|
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
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 {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
cmd := newRemoveCommand(
|
|
|
|
test.NewFakeCli(&fakeClient{
|
|
|
|
volumeRemoveFunc: tc.volumeRemoveFunc,
|
|
|
|
}, buf))
|
|
|
|
cmd.SetArgs(tc.args)
|
|
|
|
cmd.SetOutput(ioutil.Discard)
|
|
|
|
assert.Error(t, cmd.Execute(), tc.expectedError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeRemoveMultiple(t *testing.T) {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
|
|
|
|
cmd.SetArgs([]string{"volume1", "volume2"})
|
|
|
|
assert.NilError(t, cmd.Execute())
|
|
|
|
}
|