Skip to content

Commit

Permalink
test: modifying integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
talasulin committed Sep 3, 2024
1 parent 17b6713 commit 189e9c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
34 changes: 11 additions & 23 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ var _ = Describe("Successful PVC Release", func() {
}, timeout, interval).Should(Succeed())

pvcAnnotations := map[string]string{
"appsflyer.com/local-pvc-releaser": "enabled",
"appsflyer.com/local-pvc-releaser": "enabled",
"volume.kubernetes.io/selected-node": nodeName,
}
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, storageClassName, pvcAnnotations)
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, pvName, storageClassName, pvcAnnotations)
Expect(k8sClient.Create(ctx, pvc)).Should(Succeed())

// Create a PersistentVolumeClaim (PVC)
Expand Down Expand Up @@ -112,28 +113,14 @@ var _ = Describe("Ignoring PVC cleanup", func() {
objects.Helper().Event().DeleteAll(ctx, k8sClient)
})
Context("When Receiving event on node-termination", func() {
It("Should ignore as the PV is not bounded to PVC", func() {
By("By Creating a PV and PVC objects with different storage class and triggering node termination event")
pv := objects.Helper().PersistentVolume().Create(pvName, nodeName, storageClassName)
Expect(k8sClient.Create(ctx, pv)).Should(Succeed())

fetchedPv := &v1.PersistentVolume{}
Eventually(func() error {
if err := k8sClient.Get(ctx, types.NamespacedName{Name: pv.Name, Namespace: pv.Namespace}, fetchedPv); err != nil {
return err
}

if fetchedPv.Name != pv.Name {
return errors.New("Unable to find the PV after creation, creation failed")
}

return nil
}, timeout, interval).Should(Succeed())
It("Should ignore as there are no PVs attached", func() {
By("By Creating only a PVC object")

pvcAnnotations := map[string]string{
"appsflyer.com/local-pvc-releaser": "enabled",
"appsflyer.com/local-pvc-releaser": "enabled",
"volume.kubernetes.io/selected-node": nodeName,
}
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, "different-storage-class", pvcAnnotations)
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, "", "different-storage-class", pvcAnnotations)
Expect(k8sClient.Create(ctx, pvc)).Should(Succeed())

// Create a PersistentVolumeClaim (PVC)
Expand Down Expand Up @@ -210,9 +197,10 @@ var _ = Describe("Ignoring PVC cleanup", func() {
}, timeout, interval).Should(Succeed())

pvcAnnotations := map[string]string{
"test-should-fail": "true",
"test-should-fail": "true",
"volume.kubernetes.io/selected-node": nodeName,
}
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, "different-storage-class", pvcAnnotations)
pvc := objects.Helper().PersistentVolumeClaim().Create(pvcName, pvName, "different-storage-class", pvcAnnotations)
Expect(k8sClient.Create(ctx, pvc)).Should(Succeed())

// Create a PersistentVolumeClaim (PVC)
Expand Down
5 changes: 3 additions & 2 deletions test/objects/PersistentVolumeClaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type PVC interface {
Create(name, storageClassName string, annotations map[string]string) *corev1.PersistentVolumeClaim
Create(name, pvName string, storageClassName string, annotations map[string]string) *corev1.PersistentVolumeClaim
DeleteAll(ctx context.Context, client client.Client)
RemoveProtectionFinalizer(ctx context.Context, client client.Client, pvc *corev1.PersistentVolumeClaim, finalizerName string) error
}
Expand All @@ -24,7 +24,7 @@ func NewPVC() PVC {
return &persistentVolumeClaim{}
}

func (_ persistentVolumeClaim) Create(name, storageClassName string, annotations map[string]string) *corev1.PersistentVolumeClaim {
func (_ persistentVolumeClaim) Create(name, pvName string, storageClassName string, annotations map[string]string) *corev1.PersistentVolumeClaim {
pvc := &corev1.PersistentVolumeClaim{
TypeMeta: metav1.TypeMeta{
Kind: "PersistentVolumeClaim",
Expand All @@ -46,6 +46,7 @@ func (_ persistentVolumeClaim) Create(name, storageClassName string, annotations
},
},
StorageClassName: &storageClassName,
VolumeName: pvName,
},
}

Expand Down

0 comments on commit 189e9c7

Please sign in to comment.