Add stop, pause and unpause to integration test

pull/9576/head
Priya Wadhwa 2020-10-28 13:58:53 -07:00
parent d9dc4efa4d
commit 35c33c1ac6
3 changed files with 50 additions and 28 deletions

View File

@ -80,6 +80,7 @@ func trySSHPowerOff(h *host.Host) error {
return nil
}
register.Reg.SetStep(register.PowerOff)
out.T(style.Shutdown, `Powering off "{{.profile_name}}" via SSH ...`, out.V{"profile_name": h.Name})
// differnet for kic because RunSSHCommand is not implemented by kic
if driver.IsKIC(h.DriverName) {

View File

@ -39,6 +39,7 @@ const (
Done RegStep = "Done"
Stopping RegStep = "Stopping"
PowerOff RegStep = "PowerOff"
Deleting RegStep = "Deleting"
Pausing RegStep = "Pausing"
Unpausing RegStep = "Unpausing"
@ -78,7 +79,7 @@ func init() {
Done,
},
Stopping: {Stopping, Done},
Stopping: {Stopping, PowerOff, Done},
Pausing: {Pausing, Done},
Unpausing: {Unpausing, Done},
Deleting: {Deleting, Stopping, Deleting, Done},
@ -126,5 +127,3 @@ func (r *Register) SetStep(s RegStep) {
r.current = s
}
// recordStep records the current step

View File

@ -36,34 +36,56 @@ func TestJSONOutput(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
defer Cleanup(t, profile, cancel)
startArgs := []string{"start", "-p", profile, "--memory=2200", "--output=json", "--wait=true"}
startArgs = append(startArgs, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
tests := []struct {
command string
args []string
}{
{
command: "start",
args: append([]string{"--memory=2200", "--wait=true"}, StartArgs()...),
}, {
command: "pause",
}, {
command: "unpause",
}, {
command: "stop",
},
}
ces, err := cloudEvents(t, rr)
if err != nil {
t.Fatalf("converting to cloud events: %v\n", err)
}
for _, test := range tests {
t.Run(test.command, func(t *testing.T) {
args := []string{test.command, "-p", profile, "--output=json"}
args = append(args, test.args...)
type validateJSONOutputFunc func(context.Context, *testing.T, []*cloudEvent)
t.Run("serial", func(t *testing.T) {
serialTests := []struct {
name string
validator validateJSONOutputFunc
}{
{"DistinctCurrentSteps", validateDistinctCurrentSteps},
{"IncreasingCurrentSteps", validateIncreasingCurrentSteps},
}
for _, stc := range serialTests {
t.Run(stc.name, func(t *testing.T) {
stc.validator(ctx, t, ces)
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
}
ces, err := cloudEvents(t, rr)
if err != nil {
t.Fatalf("converting to cloud events: %v\n", err)
}
type validateJSONOutputFunc func(context.Context, *testing.T, []*cloudEvent)
t.Run("parallel", func(t *testing.T) {
parallelTests := []struct {
name string
validator validateJSONOutputFunc
}{
{"DistinctCurrentSteps", validateDistinctCurrentSteps},
{"IncreasingCurrentSteps", validateIncreasingCurrentSteps},
}
for _, stc := range parallelTests {
stc := stc
t.Run(stc.name, func(t *testing.T) {
MaybeParallel(t)
stc.validator(ctx, t, ces)
})
}
})
}
})
})
}
}
// make sure each step has a distinct step number
@ -100,7 +122,7 @@ func validateIncreasingCurrentSteps(ctx context.Context, t *testing.T, ces []*cl
}
}
func TestJSONOutputError(t *testing.T) {
func TestJxSONOutputError(t *testing.T) {
profile := UniqueProfileName("json-output-error")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(2))
defer Cleanup(t, profile, cancel)