Skip to content

Commit

Permalink
fix(golangci): fix checking return error status
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed Jan 4, 2024
1 parent 51bdad0 commit c3ba65b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions controllers/component/component_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ = Describe("Component Adapter", Ordered, func() {
})
snapshots := &applicationapiv1alpha1.SnapshotList{}
Eventually(func() bool {
k8sClient.List(ctx, snapshots, &client.ListOptions{Namespace: hasApp.Namespace})
Expect(k8sClient.List(ctx, snapshots, &client.ListOptions{Namespace: hasApp.Namespace})).To(Succeed())
return len(snapshots.Items) == 0
}, time.Second*20).Should(BeTrue())

Expand All @@ -138,7 +138,7 @@ var _ = Describe("Component Adapter", Ordered, func() {
result, err := adapter.EnsureComponentIsCleanedUp()

Eventually(func() bool {
k8sClient.List(ctx, snapshots, &client.ListOptions{Namespace: hasApp.Namespace})
Expect(k8sClient.List(ctx, snapshots, &client.ListOptions{Namespace: hasApp.Namespace})).To(Succeed())
return !result.CancelRequest && len(snapshots.Items) == 1 && err == nil
}, time.Second*20).Should(BeTrue())
})
Expand Down
23 changes: 15 additions & 8 deletions controllers/snapshot/snapshot_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
})

It("ensures global Component Image will not be updated in the PR context", func() {
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshotPR, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshotPR, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshotPR)).To(BeTrue())
adapter.snapshot = hasSnapshotPR

Expand All @@ -521,7 +522,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
})

It("no error from ensuring global Component Image updated when AppStudio Tests failed", func() {
gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
_, err := gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeFalse())
adapter.snapshot = hasSnapshot
result, err := adapter.EnsureGlobalCandidateImageUpdated()
Expand All @@ -533,7 +535,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
})

It("ensures global Component Image updated when AppStudio Tests succeeded", func() {
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
adapter.snapshot = hasSnapshot

Expand Down Expand Up @@ -565,7 +568,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
log := helpers.IntegrationLogger{Logger: buflogr.NewWithBuffer(&buf)}

gitops.SetSnapshotIntegrationStatusAsFinished(hasSnapshot, "Snapshot integration status condition is finished since all testing pipelines completed")
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsFinished(hasSnapshot)).To(BeTrue())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
adapter = NewAdapter(hasSnapshot, hasApp, hasComp, log, loader.NewMockLoader(), k8sClient, ctx)
Expand Down Expand Up @@ -704,7 +708,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
It("ensures snapshot environmentBinding exists", func() {
log := helpers.IntegrationLogger{Logger: buflogr.NewWithBuffer(&buf)}

gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
hasSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel] = gitops.PipelineAsCodePushType
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
adapter = NewAdapter(hasSnapshot, hasApp, hasComp, log, loader.NewMockLoader(), k8sClient, ctx)
Expand Down Expand Up @@ -793,7 +798,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
}
Expect(k8sClient.Create(ctx, hasBinding)).Should(Succeed())

gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
hasSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel] = gitops.PipelineAsCodePushType
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
})
Expand Down Expand Up @@ -967,7 +973,8 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
log := helpers.IntegrationLogger{Logger: buflogr.NewWithBuffer(&buf)}

BeforeAll(func() {
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
})

Expand Down Expand Up @@ -1737,7 +1744,7 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
statuses, err := intgteststat.NewSnapshotIntegrationTestStatuses("")
Expect(err).To(Succeed())
statuses.UpdateTestStatusIfChanged(integrationTestScenarioWithoutEnv.Name, intgteststat.IntegrationTestStatusInProgress, fakeDetails)
statuses.UpdateTestPipelineRunName(integrationTestScenarioWithoutEnv.Name, fakePLRName)
Expect(statuses.UpdateTestPipelineRunName(integrationTestScenarioWithoutEnv.Name, fakePLRName)).To(Succeed())
Expect(gitops.WriteIntegrationTestStatusesIntoSnapshot(hasSnapshot, statuses, k8sClient, ctx)).Should(Succeed())

// add rerun label
Expand Down
3 changes: 2 additions & 1 deletion gitops/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {
})

It("ensures Binding Component is created", func() {
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
bindingComponents := gitops.NewBindingComponents(hasSnapshot)
Expect(bindingComponents).NotTo(BeNil())
Expand Down
11 changes: 5 additions & 6 deletions gitops/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,14 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {

It("ensures that latest update annotation can be set and get from snapshot", func() {
t := time.Time{}
t.UnmarshalText([]byte("2023-08-26T17:57:50+02:00"))
Expect(t.UnmarshalText([]byte("2023-08-26T17:57:50+02:00"))).To(Succeed())
Expect(gitops.GetLatestUpdateTime(hasSnapshot)).To(Equal(t))
//set different time
t.UnmarshalText([]byte("2023-08-26T18:57:50+02:00"))
gitops.SetLatestUpdateTime(hasSnapshot, t)
Expect(t.UnmarshalText([]byte("2023-08-26T18:57:50+02:00"))).To(Succeed())
Expect(gitops.SetLatestUpdateTime(hasSnapshot, t)).To(Succeed())
Expect(hasSnapshot.GetAnnotations()[gitops.SnapshotPRLastUpdate]).To(Equal("2023-08-26T18:57:50+02:00"))
//set latest update time to nil
t.UnmarshalText([]byte(""))
gitops.SetLatestUpdateTime(hasSnapshot, t)
//set latest update time to zero
Expect(gitops.SetLatestUpdateTime(hasSnapshot, time.Time{})).To(Succeed())
Expect(hasSnapshot.GetAnnotations()[gitops.SnapshotPRLastUpdate]).To(Equal("0001-01-01T00:00:00Z"))

})
Expand Down
15 changes: 10 additions & 5 deletions helpers/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(pipelineRunOutcome.HasPipelineRunValidTestOutputs()).To(BeTrue())
Expect(pipelineRunOutcome.GetValidationErrorsList()).Should(BeEmpty())

gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err = gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
})

Expand Down Expand Up @@ -751,7 +752,8 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(pipelineRunOutcome.HasPipelineRunValidTestOutputs()).To(BeTrue())
Expect(pipelineRunOutcome.GetValidationErrorsList()).Should(BeEmpty())

gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err = gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
})

Expand All @@ -772,7 +774,8 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(pipelineRunOutcome.HasPipelineRunValidTestOutputs()).To(BeTrue())
Expect(pipelineRunOutcome.GetValidationErrorsList()).Should(BeEmpty())

gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
_, err = gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeFalse())
})

Expand Down Expand Up @@ -808,7 +811,8 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(pipelineRunOutcome.HasPipelineRunValidTestOutputs()).To(BeTrue())
Expect(pipelineRunOutcome.GetValidationErrorsList()).Should(BeEmpty())

gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
_, err = gitops.MarkSnapshotAsFailed(k8sClient, ctx, hasSnapshot, "test failed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeFalse())
})

Expand Down Expand Up @@ -887,7 +891,8 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(pipelineRunOutcome.HasPipelineRunValidTestOutputs()).To(BeTrue())
Expect(pipelineRunOutcome.GetValidationErrorsList()).Should(BeEmpty())

gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err = gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())
})

Expand Down
3 changes: 2 additions & 1 deletion loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ var _ = Describe("Loader", Ordered, func() {
Expect(k8sClient).NotTo(BeNil())
Expect(ctx).NotTo(BeNil())
Expect(hasSnapshot).NotTo(BeNil())
gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
_, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "test passed")
Expect(err).To(Succeed())
Expect(gitops.HaveAppStudioTestsSucceeded(hasSnapshot)).To(BeTrue())

// Normally we would Ensure that releases exist here, but that requires
Expand Down

0 comments on commit c3ba65b

Please sign in to comment.