@@ -3,6 +3,7 @@ package checkpoint
33import (
44 "errors"
55 "io"
6+ "strconv"
67 "strings"
78 "testing"
89
@@ -48,26 +49,39 @@ func TestCheckpointCreateErrors(t *testing.T) {
4849}
4950
5051func TestCheckpointCreateWithOptions (t * testing.T ) {
51- var containerID , checkpointID , checkpointDir string
52- var exit bool
53- cli := test .NewFakeCli (& fakeClient {
54- checkpointCreateFunc : func (container string , options checkpoint.CreateOptions ) error {
55- containerID = container
56- checkpointID = options .CheckpointID
57- checkpointDir = options .CheckpointDir
58- exit = options .Exit
59- return nil
60- },
61- })
62- cmd := newCreateCommand (cli )
63- cp := "checkpoint-bar"
64- cmd .SetArgs ([]string {"container-foo" , cp })
65- cmd .Flags ().Set ("leave-running" , "true" )
66- cmd .Flags ().Set ("checkpoint-dir" , "/dir/foo" )
67- assert .NilError (t , cmd .Execute ())
68- assert .Check (t , is .Equal ("container-foo" , containerID ))
69- assert .Check (t , is .Equal (cp , checkpointID ))
70- assert .Check (t , is .Equal ("/dir/foo" , checkpointDir ))
71- assert .Check (t , is .Equal (false , exit ))
72- assert .Check (t , is .Equal (cp , strings .TrimSpace (cli .OutBuffer ().String ())))
52+ const (
53+ containerName = "container-foo"
54+ checkpointName = "checkpoint-bar"
55+ checkpointDir = "/dir/foo"
56+ )
57+
58+ for _ , tc := range []bool {true , false } {
59+ leaveRunning := strconv .FormatBool (tc )
60+ t .Run ("leave-running=" + leaveRunning , func (t * testing.T ) {
61+ var actualContainerName string
62+ var actualOptions checkpoint.CreateOptions
63+ cli := test .NewFakeCli (& fakeClient {
64+ checkpointCreateFunc : func (container string , options checkpoint.CreateOptions ) error {
65+ actualContainerName = container
66+ actualOptions = options
67+ return nil
68+ },
69+ })
70+ cmd := newCreateCommand (cli )
71+ cmd .SetOut (io .Discard )
72+ cmd .SetErr (io .Discard )
73+ cmd .SetArgs ([]string {containerName , checkpointName })
74+ assert .Check (t , cmd .Flags ().Set ("leave-running" , leaveRunning ))
75+ assert .Check (t , cmd .Flags ().Set ("checkpoint-dir" , checkpointDir ))
76+ assert .NilError (t , cmd .Execute ())
77+ assert .Check (t , is .Equal (actualContainerName , containerName ))
78+ expected := checkpoint.CreateOptions {
79+ CheckpointID : checkpointName ,
80+ CheckpointDir : checkpointDir ,
81+ Exit : ! tc ,
82+ }
83+ assert .Check (t , is .Equal (actualOptions , expected ))
84+ assert .Check (t , is .Equal (strings .TrimSpace (cli .OutBuffer ().String ()), checkpointName ))
85+ })
86+ }
7387}
0 commit comments