Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Hinteregger <[email protected]>
  • Loading branch information
philipp-hinteregger committed Nov 23, 2022
1 parent 71912ee commit f4e0580
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
6 changes: 4 additions & 2 deletions operator/controllers/common/phasehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ func TestPhaseHandler_GetEvaluationFailureReasons(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_ = v1alpha1.AddToScheme(scheme.Scheme)
err := v1alpha1.AddToScheme(scheme.Scheme)
require.Nil(t, err)
client := fake.NewClientBuilder().WithObjects(tt.clientObject).Build()
tt.handler.Client = client
result, err := tt.handler.GetEvaluationFailureReasons(context.TODO(), tt.phase, tt.object)
Expand Down Expand Up @@ -460,7 +461,8 @@ func TestPhaseHandler_GetTaskFailureReasons(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_ = v1alpha1.AddToScheme(scheme.Scheme)
err := v1alpha1.AddToScheme(scheme.Scheme)
require.Nil(t, err)
client := fake.NewClientBuilder().WithObjects(tt.clientObject).Build()
tt.handler.Client = client
result, err := tt.handler.GetTaskFailureReasons(context.TODO(), tt.phase, tt.object)
Expand Down
7 changes: 5 additions & 2 deletions operator/controllers/keptnappversion/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
utils "github.com/keptn/lifecycle-toolkit/operator/controllers/common"
"github.com/keptn/lifecycle-toolkit/operator/controllers/common/fake"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -82,8 +83,10 @@ func TestKeptnAppVersionReconciler_reconcile(t *testing.T) {

//setting up fakeclient CRD data

_ = utils.AddAppVersion(r.Client, "default", "myappversion", "1.0.0", nil, lfcv1alpha1.KeptnAppVersionStatus{Status: keptncommon.StatePending})
_ = utils.AddAppVersion(r.Client, "default", "myfinishedapp", "1.0.0", nil, createFinishedAppVersionStatus())
err := utils.AddAppVersion(r.Client, "default", "myappversion", "1.0.0", nil, lfcv1alpha1.KeptnAppVersionStatus{Status: keptncommon.StatePending})
require.Nil(t, err)
err = utils.AddAppVersion(r.Client, "default", "myfinishedapp", "1.0.0", nil, createFinishedAppVersionStatus())
require.Nil(t, err)

traces := 0
for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion operator/test/component/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ var _ = Describe("KeptnAppController", Ordered, func() {

func deleteAppInCluster(instance *klcv1alpha1.KeptnApp) {
By("Cleaning Up KeptnApp CRD ")
_ = k8sClient.Delete(ctx, instance)
err := k8sClient.Delete(ctx, instance)
logErrorIfPresent(err)
}

func assertResourceUpdated(instance *klcv1alpha1.KeptnApp) *klcv1alpha1.KeptnAppVersion {
Expand Down
8 changes: 7 additions & 1 deletion operator/test/component/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ func ignoreAlreadyExists(err error) error {

func setupManager(rec []keptncontroller.Controller) {
for _, r := range rec {
_ = r.SetupWithManager(k8sManager)
err := r.SetupWithManager(k8sManager)
Expect(err).To(BeNil())
}
}

func logErrorIfPresent(err error) {
if err != nil {
GinkgoLogr.Error(err, "Something went wrong while cleaning up the test environment")
}
}

func resetSpanRecords(tp *otelsdk.TracerProvider, spanRecorder *sdktest.SpanRecorder) {
Expand Down
6 changes: 4 additions & 2 deletions operator/test/component/taskcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ var _ = Describe("KeptnTaskController", Ordered, func() {
}, "10s").Should(Succeed())
})
AfterEach(func() {
_ = k8sClient.Delete(context.TODO(), taskDefinition)
_ = k8sClient.Delete(context.TODO(), task)
err := k8sClient.Delete(context.TODO(), taskDefinition)
logErrorIfPresent(err)
err = k8sClient.Delete(context.TODO(), task)
logErrorIfPresent(err)
})
})
})
Expand Down
6 changes: 4 additions & 2 deletions operator/test/component/workloadinstancecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ var _ = Describe("KeptnWorkloadInstanceController", Ordered, func() {
})
AfterEach(func() {
// Remember to clean up the cluster after each test
_ = k8sClient.Delete(ctx, appVersion)
_ = k8sClient.Delete(ctx, wi)
err := k8sClient.Delete(ctx, appVersion)
logErrorIfPresent(err)
err = k8sClient.Delete(ctx, wi)
logErrorIfPresent(err)
// Reset span recorder after each spec
resetSpanRecords(tracer, spanRecorder)
})
Expand Down
6 changes: 4 additions & 2 deletions scheduler/test/e2e/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var _ = Describe("[E2E] KeptnScheduler", Ordered, func() {
)
BeforeEach(func() {
DeferCleanup(func() {
_ = k8sClient.Delete(ctx, pod)
err := k8sClient.Delete(ctx, pod)
logErrorIfPresent(err)
})

//create a test Pod
Expand Down Expand Up @@ -108,7 +109,8 @@ var _ = Describe("[E2E] KeptnScheduler", Ordered, func() {
)
BeforeEach(func() {
DeferCleanup(func() {
_ = k8sClient.Delete(ctx, pod)
err := k8sClient.Delete(ctx, pod)
logErrorIfPresent(err)
})

//create a test Pod
Expand Down
6 changes: 6 additions & 0 deletions scheduler/test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func TestE2EScheduler(t *testing.T) {
RunSpecs(t, "Scheduler Suite")
}

func logErrorIfPresent(err error) {
if err != nil {
GinkgoLogr.Error(err, "Something went wrong while cleaning up the test environment")
}
}

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
ctx, cancel = context.WithCancel(context.TODO())
Expand Down

0 comments on commit f4e0580

Please sign in to comment.