Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed May 9, 2024
1 parent dfbe25e commit fa1aad2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 53 deletions.
40 changes: 19 additions & 21 deletions pkg/core/children_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var _ = Describe("Wave children Suite", func() {
var h *Handler[*appsv1.Deployment]
var m utils.Matcher
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment
var currentChildren []configObject
var mgrStopped *sync.WaitGroup
var stopMgr chan struct{}
Expand Down Expand Up @@ -102,7 +101,6 @@ var _ = Describe("Wave children Suite", func() {
m.Create(s6).Should(Succeed())

deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject // TODO: remove

m.Create(deploymentObject).Should(Succeed())

Expand Down Expand Up @@ -138,7 +136,7 @@ var _ = Describe("Wave children Suite", func() {
Context("getCurrentChildren", func() {
BeforeEach(func() {
var err error
configMaps, secrets := getChildNamesByType(podControllerDeployment)
configMaps, secrets := getChildNamesByType(deploymentObject)
currentChildren, err = h.getCurrentChildren(configMaps, secrets)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -260,7 +258,7 @@ var _ = Describe("Wave children Suite", func() {
m.Delete(s2).Should(Succeed())
m.Get(s2, timeout).ShouldNot(Succeed())

configMaps, secrets := getChildNamesByType(podControllerDeployment)
configMaps, secrets := getChildNamesByType(deploymentObject)
current, err := h.getCurrentChildren(configMaps, secrets)
Expect(err).To(HaveOccurred())
Expect(current).To(BeEmpty())
Expand All @@ -272,15 +270,15 @@ var _ = Describe("Wave children Suite", func() {
var secrets configMetadataMap

BeforeEach(func() {
configMaps, secrets = getChildNamesByType(podControllerDeployment)
configMaps, secrets = getChildNamesByType(deploymentObject)
})

It("returns ConfigMaps referenced in extra-configmaps annotations", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("test-cm1", "ns1"),
configMetadata{required: false, allKeys: true}))
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("test-cm2", "ns2"),
configMetadata{required: false, allKeys: true}))
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("local-cm1", podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("local-cm1", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

Expand All @@ -289,37 +287,37 @@ var _ = Describe("Wave children Suite", func() {
configMetadata{required: false, allKeys: true}))
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("test-secret2", "ns2"),
configMetadata{required: false, allKeys: true}))
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("local-secret1", podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("local-secret1", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

It("returns ConfigMaps referenced in Volumes", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm1.GetName(), podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm1.GetName(), deploymentObject.GetNamespace()),
configMetadata{required: true, allKeys: true}))
})

It("optional ConfigMaps referenced in Volumes are returned as optional", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("volume-optional", podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("volume-optional", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

It("optional Secrets referenced in Volumes are returned as optional", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("volume-optional", podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("volume-optional", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

It("returns ConfigMaps referenced in EnvFrom", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm2.GetName(), podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm2.GetName(), deploymentObject.GetNamespace()),
configMetadata{required: true, allKeys: true}))
})

It("optional ConfigMaps referenced in EnvFrom are returned as optional", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("envfrom-optional", podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("envfrom-optional", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

It("returns ConfigMaps referenced in Env", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm3.GetName(), podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName(cm3.GetName(), deploymentObject.GetNamespace()),
configMetadata{
required: true,
allKeys: false,
Expand All @@ -332,7 +330,7 @@ var _ = Describe("Wave children Suite", func() {
})

It("returns ConfigMaps referenced in Env as optional correctly", func() {
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("env-optional", podControllerDeployment.GetNamespace()),
Expect(configMaps).To(HaveKeyWithValue(GetNamespacedName("env-optional", deploymentObject.GetNamespace()),
configMetadata{
required: false,
allKeys: false,
Expand All @@ -343,22 +341,22 @@ var _ = Describe("Wave children Suite", func() {
})

It("returns Secrets referenced in Volumes", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s1.GetName(), podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s1.GetName(), deploymentObject.GetNamespace()),
configMetadata{required: true, allKeys: true}))
})

It("returns Secrets referenced in EnvFrom", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s2.GetName(), podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s2.GetName(), deploymentObject.GetNamespace()),
configMetadata{required: true, allKeys: true}))
})

It("optional Secrets referenced in EnvFrom are returned as optional", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("envfrom-optional", podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("envfrom-optional", deploymentObject.GetNamespace()),
configMetadata{required: false, allKeys: true}))
})

It("returns Secrets referenced in Env", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s3.GetName(), podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName(s3.GetName(), deploymentObject.GetNamespace()),
configMetadata{
required: true,
allKeys: false,
Expand All @@ -371,7 +369,7 @@ var _ = Describe("Wave children Suite", func() {
})

It("returns secrets referenced in Env as optional correctly", func() {
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("env-optional", podControllerDeployment.GetNamespace()),
Expect(secrets).To(HaveKeyWithValue(GetNamespacedName("env-optional", deploymentObject.GetNamespace()),
configMetadata{
required: false,
allKeys: false,
Expand Down Expand Up @@ -401,12 +399,12 @@ var _ = Describe("Wave children Suite", func() {
}

var err error
_, err = h.getExistingChildren(podControllerDeployment)
_, err = h.getExistingChildren(deploymentObject)
Expect(err).NotTo(HaveOccurred())
})

existingChildrenFn := func() ([]Object, error) {
return h.getExistingChildren(podControllerDeployment)
return h.getExistingChildren(deploymentObject)
}

It("returns ConfigMaps with the correct OwnerReference", func() {
Expand Down
4 changes: 1 addition & 3 deletions pkg/core/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var _ = Describe("Wave migration Suite", func() {
var h *Handler[*appsv1.Deployment]
var m utils.Matcher
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment
var mgrStopped *sync.WaitGroup
var stopMgr chan struct{}

Expand Down Expand Up @@ -66,7 +65,6 @@ var _ = Describe("Wave migration Suite", func() {
m.Create(utils.ExampleSecret2.DeepCopy()).Should(Succeed())

deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject // TODO: remove

m.Create(deploymentObject).Should(Succeed())

Expand Down Expand Up @@ -113,7 +111,7 @@ var _ = Describe("Wave migration Suite", func() {
return obj
}, timeout).Should(Succeed())

_, err := h.handlePodController(podControllerDeployment)
_, err := h.handlePodController(deploymentObject)
Expect(err).NotTo(HaveOccurred())
})

Expand Down
12 changes: 5 additions & 7 deletions pkg/core/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ import (

var _ = Describe("Wave finalizer Suite", func() {
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment

BeforeEach(func() {
deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject // TODO: remove
})

Context("removeFinalizer", func() {
It("removes the wave finalizer from the deployment", func() {
f := deploymentObject.GetFinalizers()
f = append(f, FinalizerString)
deploymentObject.SetFinalizers(f)
removeFinalizer(podControllerDeployment)
removeFinalizer(deploymentObject)

Expect(deploymentObject.GetFinalizers()).NotTo(ContainElement(FinalizerString))
})
Expand All @@ -46,7 +44,7 @@ var _ = Describe("Wave finalizer Suite", func() {
f := deploymentObject.GetFinalizers()
f = append(f, "kubernetes")
deploymentObject.SetFinalizers(f)
removeFinalizer(podControllerDeployment)
removeFinalizer(deploymentObject)

Expect(deploymentObject.GetFinalizers()).To(ContainElement("kubernetes"))
})
Expand All @@ -58,18 +56,18 @@ var _ = Describe("Wave finalizer Suite", func() {
f = append(f, FinalizerString)
deploymentObject.SetFinalizers(f)

Expect(hasFinalizer(podControllerDeployment)).To(BeTrue())
Expect(hasFinalizer(deploymentObject)).To(BeTrue())
})

It("returns false if the deployment doesn't have the finalizer", func() {
// Test without any finalizers
Expect(hasFinalizer(podControllerDeployment)).To(BeFalse())
Expect(hasFinalizer(deploymentObject)).To(BeFalse())

// Test with a different finalizer
f := deploymentObject.GetFinalizers()
f = append(f, "kubernetes")
deploymentObject.SetFinalizers(f)
Expect(hasFinalizer(podControllerDeployment)).To(BeFalse())
Expect(hasFinalizer(deploymentObject)).To(BeFalse())
})
})
})
6 changes: 2 additions & 4 deletions pkg/core/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,13 @@ var _ = Describe("Wave hash Suite", func() {

Context("setConfigHash", func() {
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment // TODO: remove

BeforeEach(func() {
deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject
})

It("sets the hash annotation to the provided value", func() {
setConfigHash(podControllerDeployment, "1234")
setConfigHash(deploymentObject, "1234")

podAnnotations := deploymentObject.Spec.Template.GetAnnotations()
Expect(podAnnotations).NotTo(BeNil())
Expand All @@ -354,7 +352,7 @@ var _ = Describe("Wave hash Suite", func() {
deploymentObject.Spec.Template.SetAnnotations(podAnnotations)

// Set the config hash
setConfigHash(podControllerDeployment, "1234")
setConfigHash(deploymentObject, "1234")

// Check the existing annotation is still in place
podAnnotations = deploymentObject.Spec.Template.GetAnnotations()
Expand Down
4 changes: 1 addition & 3 deletions pkg/core/owner_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var _ = Describe("Wave owner references Suite", func() {
var h *Handler[*appsv1.Deployment]
var m utils.Matcher
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment
var mgrStopped *sync.WaitGroup
var stopMgr chan struct{}

Expand Down Expand Up @@ -83,7 +82,6 @@ var _ = Describe("Wave owner references Suite", func() {
m.Create(s3).Should(Succeed())

deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject // TODO: remove

m.Create(deploymentObject).Should(Succeed())

Expand Down Expand Up @@ -121,7 +119,7 @@ var _ = Describe("Wave owner references Suite", func() {
}

children := []Object{cm1, s1}
err := h.removeOwnerReferences(podControllerDeployment, children)
err := h.removeOwnerReferences(deploymentObject, children)
Expect(err).NotTo(HaveOccurred())
})

Expand Down
8 changes: 3 additions & 5 deletions pkg/core/required_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (

var _ = Describe("Wave required annotation Suite", func() {
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment

BeforeEach(func() {
deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject // TODO: remove
})

Context("hasRequiredAnnotation", func() {
Expand All @@ -41,7 +39,7 @@ var _ = Describe("Wave required annotation Suite", func() {
annotations[RequiredAnnotation] = requiredAnnotationValue
deploymentObject.SetAnnotations(annotations)

Expect(hasRequiredAnnotation(podControllerDeployment)).To(BeTrue())
Expect(hasRequiredAnnotation(deploymentObject)).To(BeTrue())
})

It("returns false when the annotation has value other than true", func() {
Expand All @@ -52,11 +50,11 @@ var _ = Describe("Wave required annotation Suite", func() {
annotations[RequiredAnnotation] = "false"
deploymentObject.SetAnnotations(annotations)

Expect(hasRequiredAnnotation(podControllerDeployment)).To(BeFalse())
Expect(hasRequiredAnnotation(deploymentObject)).To(BeFalse())
})

It("returns false when the annotation is not set", func() {
Expect(hasRequiredAnnotation(podControllerDeployment)).To(BeFalse())
Expect(hasRequiredAnnotation(deploymentObject)).To(BeFalse())
})

})
Expand Down
18 changes: 8 additions & 10 deletions pkg/core/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,47 @@ import (

var _ = Describe("Wave scheduler Suite", func() {
var deploymentObject *appsv1.Deployment
var podControllerDeployment *appsv1.Deployment

BeforeEach(func() {
deploymentObject = utils.ExampleDeployment.DeepCopy()
podControllerDeployment = deploymentObject
})

Context("When scheduler is disabled", func() {
BeforeEach(func() {
disableScheduling(podControllerDeployment)
disableScheduling(deploymentObject)
})

It("Sets the annotations and stores the previous scheduler", func() {
annotations := podControllerDeployment.GetAnnotations()
annotations := deploymentObject.GetAnnotations()
Expect(annotations[SchedulingDisabledAnnotation]).To(Equal("default-scheduler"))
})

It("Disables scheduling", func() {
podTemplate := GetPodTemplate(podControllerDeployment)
podTemplate := GetPodTemplate(deploymentObject)
Expect(podTemplate.Spec.SchedulerName).To(Equal(SchedulingDisabledSchedulerName))
})

It("Is reports as disabled", func() {
Expect(isSchedulingDisabled(podControllerDeployment)).To(BeTrue())
Expect(isSchedulingDisabled(deploymentObject)).To(BeTrue())
})

Context("And Is Restored", func() {
BeforeEach(func() {
restoreScheduling(podControllerDeployment)
restoreScheduling(deploymentObject)
})

It("Removes the annotations", func() {
annotations := podControllerDeployment.GetAnnotations()
annotations := deploymentObject.GetAnnotations()
Expect(annotations).NotTo(HaveKey(SchedulingDisabledAnnotation))
})

It("Restores the scheduler", func() {
podTemplate := GetPodTemplate(podControllerDeployment)
podTemplate := GetPodTemplate(deploymentObject)
Expect(podTemplate.Spec.SchedulerName).To(Equal("default-scheduler"))
})

It("Is does not report as disabled", func() {
Expect(isSchedulingDisabled(podControllerDeployment)).To(BeFalse())
Expect(isSchedulingDisabled(deploymentObject)).To(BeFalse())
})

})
Expand Down

0 comments on commit fa1aad2

Please sign in to comment.