Skip to content

Commit 642583e

Browse files
authored
Merge pull request #16492 from spowelljr/addSetupSubtest
testing: added Setup subtest for ImageBuild
2 parents f5c9d09 + b054124 commit 642583e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

site/content/en/docs/contrib/tests.en.md

+3
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ tests the functionality of the gVisor addon
449449
## TestImageBuild
450450
makes sure the 'minikube image build' command works fine
451451

452+
#### validateSetupImageBuild
453+
starts a cluster for the image builds
454+
452455
#### validateNormalImageBuild
453456
is normal test case for minikube image build, with -t parameter
454457

test/integration/image_test.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ func TestImageBuild(t *testing.T) {
3535
type validateFunc func(context.Context, *testing.T, string)
3636
profile := UniqueProfileName("image")
3737
ctx, cancel := context.WithTimeout(context.Background(), Minutes(15))
38-
startArgs := []string{"start", "-p", profile}
39-
startArgs = append(startArgs, StartArgs()...)
40-
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
4138
defer Cleanup(t, profile, cancel)
42-
if err != nil {
43-
t.Fatalf("failed to start minikube with args: %q : %v", rr.Command(), err)
44-
}
4539

4640
// Serial tests
4741
t.Run("serial", func(t *testing.T) {
4842
tests := []struct {
4943
name string
5044
validator validateFunc
5145
}{
46+
{"Setup", validateSetupImageBuild},
5247
{"NormalBuild", validateNormalImageBuild},
5348
{"BuildWithBuildArg", validateImageBuildWithBuildArg},
5449
{"BuildWithDockerIgnore", validateImageBuildWithDockerIgnore},
@@ -58,14 +53,24 @@ func TestImageBuild(t *testing.T) {
5853
for _, tc := range tests {
5954
t.Run(tc.name, func(t *testing.T) {
6055
tc.validator(ctx, t, profile)
61-
if t.Failed() && *postMortemLogs {
62-
PostMortemLogs(t, profile)
63-
}
6456
})
57+
// if setup fails bail
58+
if tc.name == "Setup" && t.Failed() {
59+
return
60+
}
6561
}
6662
})
6763
}
6864

65+
// validateSetupImageBuild starts a cluster for the image builds
66+
func validateSetupImageBuild(ctx context.Context, t *testing.T, profile string) {
67+
defer PostMortemLogs(t, profile)
68+
startArgs := append([]string{"start", "-p", profile}, StartArgs()...)
69+
if rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...)); err != nil {
70+
t.Fatalf("failed to start minikube with args: %q : %v", rr.Command(), err)
71+
}
72+
}
73+
6974
// validateNormalImageBuild is normal test case for minikube image build, with -t parameter
7075
func validateNormalImageBuild(ctx context.Context, t *testing.T, profile string) {
7176
defer PostMortemLogs(t, profile)

0 commit comments

Comments
 (0)