Skip to content

Commit

Permalink
Merge pull request #3041 from jonathanbeber/backport_3306_07
Browse files Browse the repository at this point in the history
[backport 0.7] Remove os.Exit calls from TestMain
  • Loading branch information
k8s-ci-robot authored Dec 21, 2021
2 parents ec1da9b + 040ba7a commit a79d123
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 50 deletions.
5 changes: 1 addition & 4 deletions api/v1alpha3/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha3

import (
"fmt"
"os"
"path"
"testing"

Expand Down Expand Up @@ -52,11 +51,9 @@ func TestAPIs(t *testing.T) {
}

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand Down
6 changes: 2 additions & 4 deletions api/v1alpha4/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha4

import (
"fmt"
"os"
"path"
"testing"

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

func TestMain(m *testing.M) {
setup()
code := m.Run()
teardown()
os.Exit(code)
defer teardown()
m.Run()
}

func setup() {
Expand Down
9 changes: 3 additions & 6 deletions bootstrap/eks/api/v1alpha3/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha3

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -36,21 +35,19 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
utilruntime.Must(AddToScheme(scheme.Scheme))
utilruntime.Must(bootstrapv1alpha4.AddToScheme(scheme.Scheme))

testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
path.Join("bootstrap", "eks", "config", "crd", "bases"),
path.Join("config", "crd", "bases"),
},
).WithWebhookConfiguration("unmanaged", path.Join("bootstrap", "eks", "config", "webhook", "manifests.yaml"))
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
var err error
testEnv, err = testEnvConfig.Build()
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions bootstrap/eks/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -37,11 +36,8 @@ var (

func TestMain(m *testing.M) {
setup()
defer func() {
teardown()
}()
code := m.Run()
os.Exit(code) // nolint:gocritic
defer teardown()
m.Run()
}

func setup() {
Expand Down
5 changes: 1 addition & 4 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -37,11 +36,9 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand Down
7 changes: 2 additions & 5 deletions controlplane/eks/api/v1alpha3/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha3

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -36,19 +35,17 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
utilruntime.Must(AddToScheme(scheme.Scheme))
utilruntime.Must(controlplanev1alpha4.AddToScheme(scheme.Scheme))

testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
path.Join("..", "config", "crd", "bases"),
path.Join("config", "crd", "bases"),
},
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
var err error
Expand Down
6 changes: 2 additions & 4 deletions controlplane/eks/api/v1alpha4/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha4

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -35,9 +34,8 @@ var (

func TestMain(m *testing.M) {
setup()
code := m.Run()
teardown()
os.Exit(code)
defer teardown()
m.Run()
}

func setup() {
Expand Down
5 changes: 1 addition & 4 deletions exp/api/v1alpha3/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha3

import (
"fmt"
"os"
"path"
"testing"

Expand Down Expand Up @@ -51,11 +50,9 @@ func TestAPIs(t *testing.T) {
}

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand Down
6 changes: 1 addition & 5 deletions exp/controlleridentitycreator/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controlleridentitycreator

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -43,11 +42,9 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand All @@ -57,7 +54,6 @@ func setup() {

testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
path.Join("config", "crd", "bases"),
path.Join("controlplane", "eks", "config", "crd", "bases"),
},
).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
var err error
Expand Down
5 changes: 1 addition & 4 deletions exp/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"fmt"
"os"
"path"
"testing"

Expand All @@ -42,11 +41,9 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand Down
5 changes: 1 addition & 4 deletions exp/instancestate/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package instancestate

import (
"fmt"
"os"
"path"
"testing"

Expand Down Expand Up @@ -47,11 +46,9 @@ var (
)

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
setup()
defer teardown()
code = m.Run()
m.Run()
}

func setup() {
Expand Down

0 comments on commit a79d123

Please sign in to comment.