Skip to content

Commit

Permalink
test: use utilruntime package wrap AddToScheme method (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 authored Mar 23, 2024
1 parent 78e7c2f commit dab898f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 45 deletions.
27 changes: 7 additions & 20 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -109,26 +110,12 @@ func TestMain(m *testing.M) {
fmt.Printf("failed to start testEnv: %v", err)
os.Exit(1)
}
if err = monitoringv1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = networkingv1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = routev1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1beta1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}

utilruntime.Must(monitoringv1.AddToScheme(testScheme))
utilruntime.Must(networkingv1.AddToScheme(testScheme))
utilruntime.Must(routev1.AddToScheme(testScheme))
utilruntime.Must(v1alpha1.AddToScheme(testScheme))
utilruntime.Must(v1beta1.AddToScheme(testScheme))

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
Expand Down
11 changes: 3 additions & 8 deletions internal/webhook/podmutation/webhookhandler_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -57,14 +58,8 @@ var (
func TestMain(m *testing.M) {
ctx, cancel = context.WithCancel(context.TODO())
defer cancel()
if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1beta1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
utilruntime.Must(v1alpha1.AddToScheme(testScheme))
utilruntime.Must(v1beta1.AddToScheme(testScheme))

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
Expand Down
12 changes: 3 additions & 9 deletions pkg/collector/upgrade/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -57,15 +58,8 @@ var (
func TestMain(m *testing.M) {
ctx, cancel = context.WithCancel(context.TODO())
defer cancel()

if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1beta1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
utilruntime.Must(v1alpha1.AddToScheme(testScheme))
utilruntime.Must(v1beta1.AddToScheme(testScheme))

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
Expand Down
6 changes: 2 additions & 4 deletions pkg/instrumentation/instrumentation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"
"testing"

utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -47,10 +48,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
utilruntime.Must(v1alpha1.AddToScheme(testScheme))

k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions pkg/instrumentation/upgrade/upgrade_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"
"testing"

utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -47,10 +48,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
utilruntime.Must(v1alpha1.AddToScheme(testScheme))

k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
if err != nil {
Expand Down

0 comments on commit dab898f

Please sign in to comment.