From 225ce747f37373c53e2acf6f93e84bb82636bb5c Mon Sep 17 00:00:00 2001 From: Marco Bebway Date: Mon, 4 Sep 2023 10:52:47 +0200 Subject: [PATCH] Fix checkmarx issues (#128) --- e2e/cleanup/cleanup_test.go | 9 +++------ e2e/natsserver/natsserver_test.go | 3 +-- e2e/setup/setup_test.go | 19 ++++++------------- .../controller/integration_test.go | 5 +++-- .../controllersinglecr/integration_test.go | 5 +++-- .../validation/integration_test.go | 5 +++-- testutils/integration/integration.go | 6 +++--- testutils/utils.go | 9 +++++---- 8 files changed, 27 insertions(+), 34 deletions(-) diff --git a/e2e/cleanup/cleanup_test.go b/e2e/cleanup/cleanup_test.go index 36097f53..40e58973 100644 --- a/e2e/cleanup/cleanup_test.go +++ b/e2e/cleanup/cleanup_test.go @@ -49,14 +49,12 @@ func TestMain(m *testing.M) { var err error logger, err = SetupLogger() if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } clientSet, k8sClient, err = GetK8sClients() if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Delete the NATS CR. @@ -70,8 +68,7 @@ func TestMain(m *testing.M) { return errDel }) if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Run the tests and exit. diff --git a/e2e/natsserver/natsserver_test.go b/e2e/natsserver/natsserver_test.go index 98b4dff6..4f48be3d 100644 --- a/e2e/natsserver/natsserver_test.go +++ b/e2e/natsserver/natsserver_test.go @@ -40,8 +40,7 @@ func TestMain(m *testing.M) { var err error logger, err = SetupLogger() if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Run the tests and exit. diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 63052875..4daab0e0 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -51,15 +51,12 @@ func TestMain(m *testing.M) { var err error logger, err = SetupLogger() if err != nil { - logger.Error(err.Error()) - panic(err) - + logger.Fatal(err.Error()) } clientSet, k8sClient, err = GetK8sClients() if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } ctx := context.TODO() @@ -69,8 +66,7 @@ func TestMain(m *testing.M) { return client.IgnoreAlreadyExists(k8sClient.Create(ctx, Namespace())) }) if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Wait for NATS-manager deployment to get ready. @@ -84,8 +80,7 @@ func TestMain(m *testing.M) { ) } if err := waitForNATSManagerDeploymentReady(managerImage); err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Create the NATS CR used for testing. @@ -100,8 +95,7 @@ func TestMain(m *testing.M) { return errNATS }) if err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // wait for an interval for reconciliation to update status. @@ -109,8 +103,7 @@ func TestMain(m *testing.M) { // Wait for NATS CR to get ready. if err := waitForNATSCRReady(); err != nil { - logger.Error(err.Error()) - panic(err) + logger.Fatal(err.Error()) } // Run the tests and exit. diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index dc993acd..d7755efe 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -2,6 +2,7 @@ package controller_test import ( "fmt" + "log" "os" "testing" "time" @@ -34,7 +35,7 @@ func TestMain(m *testing.M) { var err error testEnvironment, err = integration.NewTestEnvironment(projectRootDir, false, nil) if err != nil { - panic(err) + log.Fatal(err) } // run tests @@ -42,7 +43,7 @@ func TestMain(m *testing.M) { // tear down test env if err = testEnvironment.TearDown(); err != nil { - panic(err) + log.Fatal(err) } os.Exit(code) diff --git a/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go b/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go index 0de00ebf..51f590e4 100644 --- a/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go +++ b/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go @@ -2,6 +2,7 @@ package controller_test import ( "fmt" + "log" "os" "testing" @@ -34,7 +35,7 @@ func TestMain(m *testing.M) { var err error testEnvironment, err = integration.NewTestEnvironment(projectRootDir, false, givenAllowedNATS) if err != nil { - panic(err) + log.Fatal(err) } // run tests @@ -42,7 +43,7 @@ func TestMain(m *testing.M) { // tear down test env if err = testEnvironment.TearDown(); err != nil { - panic(err) + log.Fatal(err) } os.Exit(code) diff --git a/internal/controller/nats/integrationtests/validation/integration_test.go b/internal/controller/nats/integrationtests/validation/integration_test.go index 50588855..1d305b0f 100644 --- a/internal/controller/nats/integrationtests/validation/integration_test.go +++ b/internal/controller/nats/integrationtests/validation/integration_test.go @@ -1,6 +1,7 @@ package validation_test import ( + "log" "os" "testing" @@ -52,7 +53,7 @@ func TestMain(m *testing.M) { var err error testEnvironment, err = integration.NewTestEnvironment(projectRootDir, true, nil) if err != nil { - panic(err) + log.Fatal(err) } // run tests @@ -60,7 +61,7 @@ func TestMain(m *testing.M) { // tear down test env if err = testEnvironment.TearDown(); err != nil { - panic(err) + log.Fatal(err) } os.Exit(code) diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index 8f946fc8..130f0fac 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -166,7 +166,7 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, mgrCtx, cancelCtx = context.WithCancel(ctrl.SetupSignalHandler()) err = ctrlMgr.Start(mgrCtx) if err != nil { - panic(err) + log.Fatal(err) } }() @@ -235,12 +235,12 @@ func (env TestEnvironment) EnsureK8sResourceUpdated(t *testing.T, obj client.Obj func (env TestEnvironment) UpdatedNATSInK8s(nats *natsv1alpha1.NATS, options ...testutils.NATSOption) error { natsOnK8s, err := env.GetNATSFromK8s(nats.Name, nats.Namespace) if err != nil { - panic(err) + log.Fatal(err) } for _, o := range options { if er := o(&natsOnK8s); er != nil { - panic(er) + log.Fatal(err) } } diff --git a/testutils/utils.go b/testutils/utils.go index f89d2319..9802d481 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -2,6 +2,7 @@ package testutils import ( "fmt" + "log" "math/rand" "time" @@ -95,7 +96,7 @@ func NewNATSStatefulSetUnStruct(opts ...Option) *unstructured.Unstructured { for _, opt := range opts { if err := opt(obj); err != nil { - panic(err) + log.Fatal(err) } } return obj @@ -115,7 +116,7 @@ func NewSecretUnStruct(opts ...Option) *unstructured.Unstructured { for _, opt := range opts { if err := opt(obj); err != nil { - panic(err) + log.Fatal(err) } } return obj @@ -126,7 +127,7 @@ func NewSecret(opts ...Option) *apiv1.Secret { err := runtime.DefaultUnstructuredConverter.FromUnstructured( NewSecretUnStruct(opts...).UnstructuredContent(), &sampleSecret) if err != nil { - panic(err) + log.Fatal(err) } return &sampleSecret } @@ -150,7 +151,7 @@ func NewNATSCR(opts ...NATSOption) *v1alpha1.NATS { for _, opt := range opts { if err := opt(nats); err != nil { - panic(err) + log.Fatal(err) } }