Skip to content

Commit 63933c1

Browse files
authored
Merge pull request #8024 from medyagh/breakdown_start_stop
integration test: break-down TestStartStop to sub-tests
2 parents 2e7d9d8 + 8b630c2 commit 63933c1

File tree

1 file changed

+127
-68
lines changed

1 file changed

+127
-68
lines changed

test/integration/start_stop_delete_test.go

+127-68
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ func TestStartStop(t *testing.T) {
8080
tc := tc
8181
t.Run(tc.name, func(t *testing.T) {
8282
MaybeParallel(t)
83-
83+
profile := UniqueProfileName(tc.name)
84+
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
85+
defer Cleanup(t, profile, cancel)
86+
type validateStartStopFunc func(context.Context, *testing.T, string, string, string, []string)
8487
if !strings.Contains(tc.name, "docker") && NoneDriver() {
8588
t.Skipf("skipping %s - incompatible with none driver", t.Name())
8689
}
8790

88-
profile := UniqueProfileName(tc.name)
89-
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
90-
defer CleanupWithLogs(t, profile, cancel)
91-
9291
waitFlag := "--wait=true"
9392
if strings.Contains(tc.name, "cni") { // wait=app_running is broken for CNI https://github.com/kubernetes/minikube/issues/7354
9493
waitFlag = "--wait=apiserver,system_pods,default_sa"
@@ -98,80 +97,140 @@ func TestStartStop(t *testing.T) {
9897
startArgs = append(startArgs, StartArgs()...)
9998
startArgs = append(startArgs, fmt.Sprintf("--kubernetes-version=%s", tc.version))
10099

101-
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
102-
if err != nil {
103-
t.Fatalf("failed starting minikube -first start-. args %q: %v", rr.Command(), err)
104-
}
100+
t.Run("serial", func(t *testing.T) {
101+
serialTests := []struct {
102+
name string
103+
validator validateStartStopFunc
104+
}{
105+
{"FirstStart", validateFirstStart},
106+
{"DeployApp", validateDeploying},
107+
{"Stop", validateStop},
108+
{"EnableAddonAfterStop", validateEnableAddonAfterStop},
109+
{"SecondStart", validateSecondStart},
110+
{"UserAppExistsAfterStop", validateAppExistsAfterStop},
111+
{"AddonExistsAfterStop", validateAddonAfterStop},
112+
{"VerifyKubernetesImages", validateKubernetesImages},
113+
{"Pause", validatePauseAfterSart},
114+
}
115+
for _, stc := range serialTests {
116+
tcName := tc.name
117+
tcVersion := tc.version
118+
stc := stc
119+
t.Run(stc.name, func(t *testing.T) {
120+
stc.validator(ctx, t, profile, tcName, tcVersion, startArgs)
121+
})
122+
}
105123

106-
if !strings.Contains(tc.name, "cni") {
107-
testPodScheduling(ctx, t, profile)
108-
}
124+
if *cleanup {
125+
// Normally handled by cleanuprofile, but not fatal there
126+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
127+
if err != nil {
128+
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
129+
}
130+
131+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "config", "get-contexts", profile))
132+
if err != nil {
133+
t.Logf("config context error: %v (may be ok)", err)
134+
}
135+
if rr.ExitCode != 1 {
136+
t.Errorf("expected exit code 1, got %d. output: %s", rr.ExitCode, rr.Output())
137+
}
138+
}
109139

110-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile, "--alsologtostderr", "-v=3"))
111-
if err != nil {
112-
t.Fatalf("failed stopping minikube - first stop-. args %q : %v", rr.Command(), err)
113-
}
140+
})
114141

115-
// The none driver never really stops
116-
if !NoneDriver() {
117-
got := Status(ctx, t, Target(), profile, "Host")
118-
if got != state.Stopped.String() {
119-
t.Fatalf("expected post-stop host status to be -%q- but got *%q*", state.Stopped, got)
120-
}
121-
}
142+
})
143+
}
144+
})
145+
}
122146

123-
// Enable an addon to assert it comes up afterwards
124-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "addons", "enable", "dashboard", "-p", profile))
125-
if err != nil {
126-
t.Fatalf("failed to enable an addon post-stop. args %q: %v", rr.Command(), err)
127-
}
147+
func validateFirstStart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
148+
defer PostMortemLogs(t, profile)
149+
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
150+
if err != nil {
151+
t.Fatalf("failed starting minikube -first start-. args %q: %v", rr.Command(), err)
152+
}
153+
}
128154

129-
rr, err = Run(t, exec.CommandContext(ctx, Target(), startArgs...))
130-
if err != nil {
131-
// Explicit fatal so that failures don't move directly to deletion
132-
t.Fatalf("failed to start minikube post-stop. args %q: %v", rr.Command(), err)
133-
}
155+
func validateDeploying(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
156+
defer PostMortemLogs(t, profile)
157+
if !strings.Contains(tcName, "cni") {
158+
testPodScheduling(ctx, t, profile)
159+
}
160+
}
134161

135-
if strings.Contains(tc.name, "cni") {
136-
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
137-
} else {
138-
if _, err := PodWait(ctx, t, profile, "default", "integration-test=busybox", Minutes(7)); err != nil {
139-
t.Fatalf("failed waiting for pod 'busybox' post-stop-start: %v", err)
140-
}
141-
if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
142-
t.Fatalf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
143-
}
144-
}
162+
func validateStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
163+
defer PostMortemLogs(t, profile)
164+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile, "--alsologtostderr", "-v=3"))
165+
if err != nil {
166+
t.Fatalf("failed stopping minikube - first stop-. args %q : %v", rr.Command(), err)
167+
}
168+
}
145169

146-
got := Status(ctx, t, Target(), profile, "Host")
147-
if got != state.Running.String() {
148-
t.Fatalf("expected host status after start-stop-start to be -%q- but got *%q*", state.Running, got)
149-
}
170+
func validateEnableAddonAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
171+
defer PostMortemLogs(t, profile)
172+
// The none driver never really stops
173+
if !NoneDriver() {
174+
got := Status(ctx, t, Target(), profile, "Host")
175+
if got != state.Stopped.String() {
176+
t.Errorf("expected post-stop host status to be -%q- but got *%q*", state.Stopped, got)
177+
}
178+
}
150179

151-
if !NoneDriver() {
152-
testPulledImages(ctx, t, profile, tc.version)
153-
}
180+
// Enable an addon to assert it comes up afterwards
181+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "addons", "enable", "dashboard", "-p", profile))
182+
if err != nil {
183+
t.Errorf("failed to enable an addon post-stop. args %q: %v", rr.Command(), err)
184+
}
154185

155-
testPause(ctx, t, profile)
186+
}
156187

157-
if *cleanup {
158-
// Normally handled by cleanuprofile, but not fatal there
159-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
160-
if err != nil {
161-
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
162-
}
188+
func validateSecondStart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
189+
defer PostMortemLogs(t, profile)
190+
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
191+
if err != nil {
192+
// Explicit fatal so that failures don't move directly to deletion
193+
t.Fatalf("failed to start minikube post-stop. args %q: %v", rr.Command(), err)
194+
}
163195

164-
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "config", "get-contexts", profile))
165-
if err != nil {
166-
t.Logf("config context error: %v (may be ok)", err)
167-
}
168-
if rr.ExitCode != 1 {
169-
t.Errorf("expected exit code 1, got %d. output: %s", rr.ExitCode, rr.Output())
170-
}
171-
}
172-
})
173-
}
174-
})
196+
got := Status(ctx, t, Target(), profile, "Host")
197+
if got != state.Running.String() {
198+
t.Errorf("expected host status after start-stop-start to be -%q- but got *%q*", state.Running, got)
199+
}
200+
201+
}
202+
203+
// validateAppExistsAfterStop verifies that a user's app will not vanish after a minikube stop
204+
func validateAppExistsAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
205+
defer PostMortemLogs(t, profile)
206+
if strings.Contains(tcName, "cni") {
207+
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
208+
} else if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
209+
t.Errorf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
210+
}
211+
212+
}
213+
214+
// validateAddonAfterStop validates that an addon which was enabled when minikube is stopped will be enabled and working..
215+
func validateAddonAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
216+
defer PostMortemLogs(t, profile)
217+
if strings.Contains(tcName, "cni") {
218+
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
219+
} else if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
220+
t.Errorf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
221+
}
222+
}
223+
224+
func validateKubernetesImages(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
225+
defer PostMortemLogs(t, profile)
226+
if !NoneDriver() {
227+
testPulledImages(ctx, t, profile, tcVersion)
228+
}
229+
}
230+
231+
func validatePauseAfterSart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
232+
defer PostMortemLogs(t, profile)
233+
testPause(ctx, t, profile)
175234
}
176235

177236
// testPodScheduling asserts that this configuration can schedule new pods

0 commit comments

Comments
 (0)