2017-06-30 17:09:37 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-21 16:30:09 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2017-06-30 17:09:37 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/pkg/errors"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-06-30 17:09:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckpointRemoveErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
|
|
|
checkpointDeleteFunc func(container string, options types.CheckpointDeleteOptions) error
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{"too-few-arguments"},
|
2017-08-12 12:25:38 -04:00
|
|
|
expectedError: "requires exactly 2 arguments",
|
2017-06-30 17:09:37 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"too", "many", "arguments"},
|
2017-08-12 12:25:38 -04:00
|
|
|
expectedError: "requires exactly 2 arguments",
|
2017-06-30 17:09:37 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"foo", "bar"},
|
|
|
|
checkpointDeleteFunc: func(container string, options types.CheckpointDeleteOptions) error {
|
|
|
|
return errors.Errorf("error deleting checkpoint")
|
|
|
|
},
|
|
|
|
expectedError: "error deleting checkpoint",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2017-08-16 11:54:23 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
2017-06-30 17:09:37 -04:00
|
|
|
checkpointDeleteFunc: tc.checkpointDeleteFunc,
|
2017-08-16 11:54:23 -04:00
|
|
|
})
|
2017-06-30 17:09:37 -04:00
|
|
|
cmd := newRemoveCommand(cli)
|
|
|
|
cmd.SetArgs(tc.args)
|
|
|
|
cmd.SetOutput(ioutil.Discard)
|
2018-03-06 14:03:47 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2017-06-30 17:09:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckpointRemoveWithOptions(t *testing.T) {
|
|
|
|
var containerID, checkpointID, checkpointDir string
|
2017-08-16 11:54:23 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
2017-06-30 17:09:37 -04:00
|
|
|
checkpointDeleteFunc: func(container string, options types.CheckpointDeleteOptions) error {
|
|
|
|
containerID = container
|
|
|
|
checkpointID = options.CheckpointID
|
|
|
|
checkpointDir = options.CheckpointDir
|
|
|
|
return nil
|
|
|
|
},
|
2017-08-16 11:54:23 -04:00
|
|
|
})
|
2017-06-30 17:09:37 -04:00
|
|
|
cmd := newRemoveCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
|
|
|
|
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("container-foo", containerID))
|
|
|
|
assert.Check(t, is.Equal("checkpoint-bar", checkpointID))
|
|
|
|
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
|
2017-06-30 17:09:37 -04:00
|
|
|
}
|