TestCheckpointCreateWithOptions check both "keep-running=true/false"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4808d1bcd2
commit
007e88ec3d
@ -3,6 +3,7 @@ package checkpoint
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -48,26 +49,39 @@ func TestCheckpointCreateErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckpointCreateWithOptions(t *testing.T) {
|
func TestCheckpointCreateWithOptions(t *testing.T) {
|
||||||
var containerID, checkpointID, checkpointDir string
|
const (
|
||||||
var exit bool
|
containerName = "container-foo"
|
||||||
|
checkpointName = "checkpoint-bar"
|
||||||
|
checkpointDir = "/dir/foo"
|
||||||
|
)
|
||||||
|
|
||||||
|
for _, tc := range []bool{true, false} {
|
||||||
|
leaveRunning := strconv.FormatBool(tc)
|
||||||
|
t.Run("leave-running="+leaveRunning, func(t *testing.T) {
|
||||||
|
var actualContainerName string
|
||||||
|
var actualOptions checkpoint.CreateOptions
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
checkpointCreateFunc: func(container string, options checkpoint.CreateOptions) error {
|
checkpointCreateFunc: func(container string, options checkpoint.CreateOptions) error {
|
||||||
containerID = container
|
actualContainerName = container
|
||||||
checkpointID = options.CheckpointID
|
actualOptions = options
|
||||||
checkpointDir = options.CheckpointDir
|
|
||||||
exit = options.Exit
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newCreateCommand(cli)
|
cmd := newCreateCommand(cli)
|
||||||
cp := "checkpoint-bar"
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs([]string{"container-foo", cp})
|
cmd.SetErr(io.Discard)
|
||||||
cmd.Flags().Set("leave-running", "true")
|
cmd.SetArgs([]string{containerName, checkpointName})
|
||||||
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
|
assert.Check(t, cmd.Flags().Set("leave-running", leaveRunning))
|
||||||
|
assert.Check(t, cmd.Flags().Set("checkpoint-dir", checkpointDir))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
assert.Check(t, is.Equal("container-foo", containerID))
|
assert.Check(t, is.Equal(actualContainerName, containerName))
|
||||||
assert.Check(t, is.Equal(cp, checkpointID))
|
expected := checkpoint.CreateOptions{
|
||||||
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
|
CheckpointID: checkpointName,
|
||||||
assert.Check(t, is.Equal(false, exit))
|
CheckpointDir: checkpointDir,
|
||||||
assert.Check(t, is.Equal(cp, strings.TrimSpace(cli.OutBuffer().String())))
|
Exit: !tc,
|
||||||
|
}
|
||||||
|
assert.Check(t, is.Equal(actualOptions, expected))
|
||||||
|
assert.Check(t, is.Equal(strings.TrimSpace(cli.OutBuffer().String()), checkpointName))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user