Skip to content

Commit a79d123

Browse files
authored
Merge pull request #3041 from jonathanbeber/backport_3306_07
[backport 0.7] Remove os.Exit calls from TestMain
2 parents ec1da9b + 040ba7a commit a79d123

File tree

11 files changed

+17
-50
lines changed

11 files changed

+17
-50
lines changed

api/v1alpha3/webhook_suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha3
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -52,11 +51,9 @@ func TestAPIs(t *testing.T) {
5251
}
5352

5453
func TestMain(m *testing.M) {
55-
code := 0
56-
defer func() { os.Exit(code) }()
5754
setup()
5855
defer teardown()
59-
code = m.Run()
56+
m.Run()
6057
}
6158

6259
func setup() {

api/v1alpha4/suite_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha4
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -47,9 +46,8 @@ func TestAPIs(t *testing.T) {
4746

4847
func TestMain(m *testing.M) {
4948
setup()
50-
code := m.Run()
51-
teardown()
52-
os.Exit(code)
49+
defer teardown()
50+
m.Run()
5351
}
5452

5553
func setup() {

bootstrap/eks/api/v1alpha3/webhook_suite_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha3
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -36,21 +35,19 @@ var (
3635
)
3736

3837
func TestMain(m *testing.M) {
39-
code := 0
40-
defer func() { os.Exit(code) }()
4138
setup()
4239
defer teardown()
43-
code = m.Run()
40+
m.Run()
4441
}
4542

4643
func setup() {
4744
utilruntime.Must(AddToScheme(scheme.Scheme))
4845
utilruntime.Must(bootstrapv1alpha4.AddToScheme(scheme.Scheme))
4946

5047
testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
51-
path.Join("bootstrap", "eks", "config", "crd", "bases"),
48+
path.Join("config", "crd", "bases"),
5249
},
53-
).WithWebhookConfiguration("unmanaged", path.Join("bootstrap", "eks", "config", "webhook", "manifests.yaml"))
50+
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
5451
var err error
5552
testEnv, err = testEnvConfig.Build()
5653
if err != nil {

bootstrap/eks/controllers/suite_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controllers
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -37,11 +36,8 @@ var (
3736

3837
func TestMain(m *testing.M) {
3938
setup()
40-
defer func() {
41-
teardown()
42-
}()
43-
code := m.Run()
44-
os.Exit(code) // nolint:gocritic
39+
defer teardown()
40+
m.Run()
4541
}
4642

4743
func setup() {

controllers/suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controllers
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -37,11 +36,9 @@ var (
3736
)
3837

3938
func TestMain(m *testing.M) {
40-
code := 0
41-
defer func() { os.Exit(code) }()
4239
setup()
4340
defer teardown()
44-
code = m.Run()
41+
m.Run()
4542
}
4643

4744
func setup() {

controlplane/eks/api/v1alpha3/webhook_suite_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha3
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -36,19 +35,17 @@ var (
3635
)
3736

3837
func TestMain(m *testing.M) {
39-
code := 0
40-
defer func() { os.Exit(code) }()
4138
setup()
4239
defer teardown()
43-
code = m.Run()
40+
m.Run()
4441
}
4542

4643
func setup() {
4744
utilruntime.Must(AddToScheme(scheme.Scheme))
4845
utilruntime.Must(controlplanev1alpha4.AddToScheme(scheme.Scheme))
4946

5047
testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
51-
path.Join("..", "config", "crd", "bases"),
48+
path.Join("config", "crd", "bases"),
5249
},
5350
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
5451
var err error

controlplane/eks/api/v1alpha4/suite_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha4
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -35,9 +34,8 @@ var (
3534

3635
func TestMain(m *testing.M) {
3736
setup()
38-
code := m.Run()
39-
teardown()
40-
os.Exit(code)
37+
defer teardown()
38+
m.Run()
4139
}
4240

4341
func setup() {

exp/api/v1alpha3/webhook_suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha3
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -51,11 +50,9 @@ func TestAPIs(t *testing.T) {
5150
}
5251

5352
func TestMain(m *testing.M) {
54-
code := 0
55-
defer func() { os.Exit(code) }()
5653
setup()
5754
defer teardown()
58-
code = m.Run()
55+
m.Run()
5956
}
6057

6158
func setup() {

exp/controlleridentitycreator/suite_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controlleridentitycreator
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -43,11 +42,9 @@ var (
4342
)
4443

4544
func TestMain(m *testing.M) {
46-
code := 0
47-
defer func() { os.Exit(code) }()
4845
setup()
4946
defer teardown()
50-
code = m.Run()
47+
m.Run()
5148
}
5249

5350
func setup() {
@@ -57,7 +54,6 @@ func setup() {
5754

5855
testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
5956
path.Join("config", "crd", "bases"),
60-
path.Join("controlplane", "eks", "config", "crd", "bases"),
6157
},
6258
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
6359
var err error

exp/controllers/suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controllers
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -42,11 +41,9 @@ var (
4241
)
4342

4443
func TestMain(m *testing.M) {
45-
code := 0
46-
defer func() { os.Exit(code) }()
4744
setup()
4845
defer teardown()
49-
code = m.Run()
46+
m.Run()
5047
}
5148

5249
func setup() {

exp/instancestate/suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package instancestate
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path"
2322
"testing"
2423

@@ -47,11 +46,9 @@ var (
4746
)
4847

4948
func TestMain(m *testing.M) {
50-
code := 0
51-
defer func() { os.Exit(code) }()
5249
setup()
5350
defer teardown()
54-
code = m.Run()
51+
m.Run()
5552
}
5653

5754
func setup() {

0 commit comments

Comments
 (0)