Skip to content

Commit

Permalink
Fix checkmarx issues (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway authored Sep 4, 2023
1 parent 17f2651 commit 225ce74
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
9 changes: 3 additions & 6 deletions e2e/cleanup/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions e2e/natsserver/natsserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 6 additions & 13 deletions e2e/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -100,17 +95,15 @@ 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.
time.Sleep(interval)

// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller_test

import (
"fmt"
"log"
"os"
"testing"
"time"
Expand Down Expand Up @@ -34,15 +35,15 @@ 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
code := m.Run()

// tear down test env
if err = testEnvironment.TearDown(); err != nil {
panic(err)
log.Fatal(err)
}

os.Exit(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller_test

import (
"fmt"
"log"
"os"
"testing"

Expand Down Expand Up @@ -34,15 +35,15 @@ 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
code := m.Run()

// tear down test env
if err = testEnvironment.TearDown(); err != nil {
panic(err)
log.Fatal(err)
}

os.Exit(code)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation_test

import (
"log"
"os"
"testing"

Expand Down Expand Up @@ -52,15 +53,15 @@ 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
code := m.Run()

// tear down test env
if err = testEnvironment.TearDown(); err != nil {
panic(err)
log.Fatal(err)
}

os.Exit(code)
Expand Down
6 changes: 3 additions & 3 deletions testutils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()

Expand Down Expand Up @@ -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)
}
}

Expand Down
9 changes: 5 additions & 4 deletions testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutils

import (
"fmt"
"log"
"math/rand"
"time"

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 225ce74

Please sign in to comment.