Skip to content

Commit

Permalink
Add extra steps to label and annotation test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamo committed Mar 8, 2022
1 parent 6fa63ea commit 4a8dfa8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
56 changes: 42 additions & 14 deletions internal/anchor/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package anchor_test

import (
"context"
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -148,12 +147,27 @@ var _ = Describe("Anchor", func() {
updateAnchor(ctx, foo_anchor_bar)
Eventually(GetLabel(ctx, barName, "legal-label")).Should(Equal("second-value"))

// Remove 'baz' as a child and verify that the label is NOT removed
bazHier := GetHierarchy(ctx, bazName)
bazHier.Spec.Parent = ""
UpdateHierarchy(ctx, bazHier)
Eventually(GetLabel(ctx, bazName, "legal-label")).Should(Equal("second-value"))
Eventually(GetHierarchy(ctx, bazName).Spec.Parent).Should(Equal("bar"))
//Remove label from hierarchyconfiguration and verify that the label is NOT removed
barHier := GetHierarchy(ctx, barName)
barHier.Spec.Labels = []api.MetaKVP{}
UpdateHierarchy(ctx, barHier)
Consistently(GetLabel(ctx, barName, "legal-label")).Should(Equal("second-value"))

//Remove subnamespace-of annotation from child namespace and verify anchor is in conflict
barNs := GetNamespace(ctx, barName)
delete(barNs.GetAnnotations(), api.SubnamespaceOf)
UpdateNamespace(ctx, barNs)
Eventually(getAnchorState(ctx, fooName, barName)).Should(Equal(api.Conflict))

//Delete parent anchor with labels and verify that label is not removed
DeleteObject(ctx, "subnamespaceanchors", fooName, barName)
Consistently(GetLabel(ctx, barName, "legal-label")).Should(Equal("second-value"))

//Remove label from hierarchyconfiguration and verify that label is removed
barHier = GetHierarchy(ctx, barName)
barHier.Spec.Labels = []api.MetaKVP{}
UpdateHierarchy(ctx, barHier)
Eventually(GetLabel(ctx, barName, "legal-label")).Should(Equal(""))
})

It("should propagate managed annotations and not unmanaged annotations", func() {
Expand Down Expand Up @@ -191,13 +205,27 @@ var _ = Describe("Anchor", func() {
updateAnchor(ctx, foo_anchor_bar)
Eventually(GetAnnotation(ctx, barName, "legal-annotation")).Should(Equal("second-value"))

// Remove 'baz' as a child and verify that the annotation is NOT removed
bazHier := GetHierarchy(ctx, bazName)
bazHier.Spec.Parent = ""
UpdateHierarchy(ctx, bazHier)
Eventually(GetAnnotation(ctx, bazName, "legal-annotation")).Should(Equal("second-value"))
println(fmt.Sprintf("BAZ: %+v", GetHierarchy(ctx, bazName)))
Eventually(GetHierarchy(ctx, bazName).Spec.Parent).Should(Equal("bar"))
//Remove annotation from hierarchyconfiguration and verify that the annotation is NOT removed
barHier := GetHierarchy(ctx, barName)
barHier.Spec.Annotations = []api.MetaKVP{}
UpdateHierarchy(ctx, barHier)
Consistently(GetAnnotation(ctx, barName, "legal-annotation")).Should(Equal("second-value"))

//Remove subnamespace-of annotation from child namespace and verify anchor is in conflict
barNs := GetNamespace(ctx, barName)
delete(barNs.GetAnnotations(), api.SubnamespaceOf)
UpdateNamespace(ctx, barNs)
Eventually(getAnchorState(ctx, fooName, barName)).Should(Equal(api.Conflict))

//Delete parent anchor with annotations and verify that annotation is not removed
DeleteObject(ctx, "subnamespaceanchors", fooName, barName)
Consistently(GetAnnotation(ctx, barName, "legal-annotation")).Should(Equal("second-value"))

//Remove label from hierarchyconfiguration and verify that annotation is removed
barHier = GetHierarchy(ctx, barName)
barHier.Spec.Annotations = []api.MetaKVP{}
UpdateHierarchy(ctx, barHier)
Eventually(GetAnnotation(ctx, barName, "legal-annotation")).Should(Equal(""))
})
})

Expand Down
3 changes: 2 additions & 1 deletion internal/integtest/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var GVKs = map[string]schema.GroupVersionKind{
"limitranges": {Group: "", Version: "v1", Kind: "LimitRange"},
"configmaps": {Group: "", Version: "v1", Kind: "ConfigMap"},
// crontabs is a custom resource.
"crontabs": {Group: "stable.example.com", Version: "v1", Kind: "CronTab"},
"crontabs": {Group: "stable.example.com", Version: "v1", Kind: "CronTab"},
"subnamespaceanchors": {Group: "hnc.x-k8s.io", Version: "v1alpha2", Kind: "SubnamespaceAnchor"},
}

// createdObjects keeps track of objects created out of the MakeObject function.
Expand Down

0 comments on commit 4a8dfa8

Please sign in to comment.