From 35c33c1ac6d3e6a7155e4cdabf2de7f4cfbed335 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 28 Oct 2020 13:58:53 -0700 Subject: [PATCH] Add stop, pause and unpause to integration test --- pkg/minikube/machine/stop.go | 1 + pkg/minikube/out/register/register.go | 5 +- test/integration/json_output_test.go | 72 +++++++++++++++++---------- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/pkg/minikube/machine/stop.go b/pkg/minikube/machine/stop.go index 4309a8cdae..54fb0f8331 100644 --- a/pkg/minikube/machine/stop.go +++ b/pkg/minikube/machine/stop.go @@ -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) { diff --git a/pkg/minikube/out/register/register.go b/pkg/minikube/out/register/register.go index f5e316c1cb..5672e7ad30 100644 --- a/pkg/minikube/out/register/register.go +++ b/pkg/minikube/out/register/register.go @@ -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 diff --git a/test/integration/json_output_test.go b/test/integration/json_output_test.go index b5085dffd7..e5033dce74 100644 --- a/test/integration/json_output_test.go +++ b/test/integration/json_output_test.go @@ -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)