mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f151c297eb
Start work on adding unit tests to our cli code in order to have to write less costly integration test. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
47 lines
1 KiB
Go
47 lines
1 KiB
Go
package node
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/cli/internal/test"
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
)
|
|
|
|
func TestNodeRemoveErrors(t *testing.T) {
|
|
testCases := []struct {
|
|
args []string
|
|
nodeRemoveFunc func() error
|
|
expectedError string
|
|
}{
|
|
{
|
|
expectedError: "requires at least 1 argument",
|
|
},
|
|
{
|
|
args: []string{"nodeID"},
|
|
nodeRemoveFunc: func() error {
|
|
return fmt.Errorf("error removing the node")
|
|
},
|
|
expectedError: "error removing the node",
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
buf := new(bytes.Buffer)
|
|
cmd := newRemoveCommand(
|
|
test.NewFakeCli(&fakeClient{
|
|
nodeRemoveFunc: tc.nodeRemoveFunc,
|
|
}, 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{"nodeID1", "nodeID2"})
|
|
assert.NilError(t, cmd.Execute())
|
|
}
|