Skip to content

Commit

Permalink
fix(HACBS-1535): add test for updating snapshot environments
Browse files Browse the repository at this point in the history
Add test coverage for
updateExistingSnapshotEnvironmentBindingWithSnapshot

Signed-off-by: Martin Basti <mbasti@redhat.com>
  • Loading branch information
MartinBasti committed Feb 16, 2023
1 parent 012b445 commit 1f031ba
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions controllers/snapshot/snapshot_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,63 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
}, time.Second*10).Should(BeTrue())
})

When("multiple components exist", func() {

var (
secondComp *applicationapiv1alpha1.Component
)

BeforeEach(func() {
secondComp = &applicationapiv1alpha1.Component{
ObjectMeta: metav1.ObjectMeta{
Name: "component-second-sample",
Namespace: "default",
},
Spec: applicationapiv1alpha1.ComponentSpec{
ComponentName: "component-second-sample",
Application: "application-sample",
ContainerImage: "",
Source: applicationapiv1alpha1.ComponentSource{
ComponentSourceUnion: applicationapiv1alpha1.ComponentSourceUnion{
GitSource: &applicationapiv1alpha1.GitSource{
URL: SampleRepoLink,
},
},
},
},
}
Expect(k8sClient.Create(ctx, secondComp)).Should(Succeed())

})

AfterEach(func() {
err := k8sClient.Delete(ctx, secondComp)
Expect(err == nil || errors.IsNotFound(err)).To(BeTrue())
})

It("ensures updating existing snapshot works", func() {
var snapshotEnvironmentBinding *applicationapiv1alpha1.SnapshotEnvironmentBinding

// create snapshot environment
components := []applicationapiv1alpha1.Component{
*hasComp,
}
snapshotEnvironmentBinding, err := adapter.createSnapshotEnvironmentBindingForSnapshot(adapter.application, &env, hasSnapshot, &components)
Expect(err).To(BeNil())
Expect(snapshotEnvironmentBinding).NotTo(BeNil())

// update snapshot environment with new component
componentsUpdate := []applicationapiv1alpha1.Component{
*secondComp,
}

updatedSnapshotEnvironmentBinding, err := adapter.updateExistingSnapshotEnvironmentBindingWithSnapshot(snapshotEnvironmentBinding, hasSnapshot, &componentsUpdate)
Expect(err).To(BeNil())
Expect(updatedSnapshotEnvironmentBinding).NotTo(BeNil())
Expect(len(updatedSnapshotEnvironmentBinding.Spec.Components) == 1)
Expect(updatedSnapshotEnvironmentBinding.Spec.Components[0].Name == secondComp.Spec.ComponentName)

})
})

})

0 comments on commit 1f031ba

Please sign in to comment.