2017-06-30 17:09:37 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
2022-02-25 07:03:17 -05:00
|
|
|
"io"
|
2017-06-30 17:09:37 -04:00
|
|
|
"testing"
|
|
|
|
|
2017-08-21 16:30:09 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2023-08-28 06:06:35 -04:00
|
|
|
"github.com/docker/docker/api/types/checkpoint"
|
2017-06-30 17:09:37 -04:00
|
|
|
"github.com/pkg/errors"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-06-30 17:09:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckpointRemoveErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
2023-08-28 06:06:35 -04:00
|
|
|
checkpointDeleteFunc func(container string, options checkpoint.DeleteOptions) error
|
2017-06-30 17:09:37 -04:00
|
|
|
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"},
|
2023-08-28 06:06:35 -04:00
|
|
|
checkpointDeleteFunc: func(container string, options checkpoint.DeleteOptions) error {
|
2017-06-30 17:09:37 -04:00
|
|
|
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)
|
2022-02-25 07:03:17 -05:00
|
|
|
cmd.SetOut(io.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{
|
2023-08-28 06:06:35 -04:00
|
|
|
checkpointDeleteFunc: func(container string, options checkpoint.DeleteOptions) error {
|
2017-06-30 17:09:37 -04:00
|
|
|
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
|
|
|
}
|