Skip to content

Commit

Permalink
add test for reconcile consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Feb 2, 2024
1 parent df5514a commit 15a63c1
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions controllers/namespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,60 @@ var _ = Describe("Namespace controller", func() {
HaveField("Annotations", HaveKeyWithValue("memo", "tama")),
))
})

Context("templated namespace", func() {
var ns1 *corev1.Namespace

BeforeEach(func() {
tmpl := &corev1.Namespace{}
tmpl.GenerateName = "tmpl"
tmpl.Labels = map[string]string{
constants.LabelType: constants.NSTypeTemplate,
"team": "label",
}
tmpl.Annotations = map[string]string{"memo": "annot"}
Expect(k8sClient.Create(ctx, tmpl)).To(Succeed())

ns1 = &corev1.Namespace{}
ns1.GenerateName = "ns1"
ns1.Labels = map[string]string{constants.LabelTemplate: tmpl.Name}
Expect(k8sClient.Create(ctx, ns1)).To(Succeed())

Eventually(komega.Object(ns1)).Should(HaveField("Labels", HaveKeyWithValue("team", "label")))
Expect(ns1.Annotations).To(HaveKeyWithValue("memo", "annot"))
})

It("should have stable resourceVersion", func() {
resourceVersion := ns1.ResourceVersion
Consistently(komega.Object(ns1)).Should(HaveField("ResourceVersion", Equal(resourceVersion)))
})
})

Context("sub namespace", func() {
var sub1 *corev1.Namespace

BeforeEach(func() {
root := &corev1.Namespace{}
root.GenerateName = "root"
root.Labels = map[string]string{
constants.LabelType: constants.NSTypeRoot,
"team": "label",
}
root.Annotations = map[string]string{"memo": "annot"}
Expect(k8sClient.Create(ctx, root)).To(Succeed())

sub1 = &corev1.Namespace{}
sub1.GenerateName = "sub1"
sub1.Labels = map[string]string{constants.LabelParent: root.Name}
Expect(k8sClient.Create(ctx, sub1)).To(Succeed())

Eventually(komega.Object(sub1)).Should(HaveField("Labels", HaveKeyWithValue("team", "label")))
Expect(sub1.Annotations).To(HaveKeyWithValue("memo", "annot"))
})

It("should have stable resourceVersion", func() {
resourceVersion := sub1.ResourceVersion
Consistently(komega.Object(sub1)).Should(HaveField("ResourceVersion", Equal(resourceVersion)))
})
})
})

0 comments on commit 15a63c1

Please sign in to comment.