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"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/golden"
|
2017-06-30 17:09:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckpointListErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
|
|
|
checkpointListFunc func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{},
|
|
|
|
expectedError: "requires exactly 1 argument",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"too", "many", "arguments"},
|
|
|
|
expectedError: "requires exactly 1 argument",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"foo"},
|
|
|
|
checkpointListFunc: func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
|
|
|
|
return []types.Checkpoint{}, errors.Errorf("error getting checkpoints for container foo")
|
|
|
|
},
|
|
|
|
expectedError: "error getting checkpoints for container foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2017-08-16 11:54:23 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
2017-06-30 17:09:37 -04:00
|
|
|
checkpointListFunc: tc.checkpointListFunc,
|
2017-08-16 11:54:23 -04:00
|
|
|
})
|
2017-06-30 17:09:37 -04:00
|
|
|
cmd := newListCommand(cli)
|
|
|
|
cmd.SetArgs(tc.args)
|
2020-05-07 08:25:59 -04:00
|
|
|
cmd.SetOut(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 TestCheckpointListWithOptions(t *testing.T) {
|
|
|
|
var containerID, checkpointDir string
|
2017-08-16 11:54:23 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
2017-06-30 17:09:37 -04:00
|
|
|
checkpointListFunc: func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
|
|
|
|
containerID = container
|
|
|
|
checkpointDir = options.CheckpointDir
|
|
|
|
return []types.Checkpoint{
|
|
|
|
{Name: "checkpoint-foo"},
|
|
|
|
}, nil
|
|
|
|
},
|
2017-08-16 11:54:23 -04:00
|
|
|
})
|
2017-06-30 17:09:37 -04:00
|
|
|
cmd := newListCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"container-foo"})
|
|
|
|
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("/dir/foo", checkpointDir))
|
2017-08-16 11:54:23 -04:00
|
|
|
golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden")
|
2017-06-30 17:09:37 -04:00
|
|
|
}
|