forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectindex_test.go
More file actions
111 lines (86 loc) · 3.21 KB
/
objectindex_test.go
File metadata and controls
111 lines (86 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package managedresource
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
)
var _ = Describe("objectIndex", func() {
Describe("#NewObjectIndex, #Lookup", func() {
It("without equivalences", func() {
oldRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "kindA", APIVersion: "groupA/v2"},
}
unusedRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "foo", Namespace: "bar", Kind: "kind", APIVersion: "group/v1"},
}
existingRefs := []v1alpha1.ObjectReference{
oldRef,
unusedRef,
}
index := NewObjectIndex(existingRefs, nil)
newRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "kindB", APIVersion: "groupB/v1"},
}
_, found := index.Lookup(newRef)
Expect(found).To(BeFalse())
foundRef, found := index.Lookup(oldRef)
Expect(found).To(BeTrue())
Expect(foundRef).To(Equal(oldRef))
Expect(index.Found(oldRef)).To(BeTrue())
Expect(index.Found(unusedRef)).To(BeFalse())
})
It("with default equivalences", func() {
oldRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "Deployment", APIVersion: "extensions/v1beta1"},
}
unusedRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "foo", Namespace: "bar", Kind: "kind", APIVersion: "group/v1"},
}
existingRefs := []v1alpha1.ObjectReference{
oldRef,
unusedRef,
}
index := NewObjectIndex(existingRefs, NewEquivalences())
newRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "Deployment", APIVersion: "apps/v1"},
}
foundRef, found := index.Lookup(newRef)
Expect(found).To(BeTrue())
Expect(foundRef).To(Equal(oldRef))
Expect(index.Found(oldRef)).To(BeTrue())
Expect(index.Found(unusedRef)).To(BeFalse())
})
It("with equivalences", func() {
equis := [][]metav1.GroupKind{
{
{Group: "groupA", Kind: "kindA"},
{Group: "groupB", Kind: "kindB"},
},
}
oldRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "kindA", APIVersion: "groupA/v2"},
}
unusedRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "foo", Namespace: "bar", Kind: "kind", APIVersion: "group/v1"},
}
existingRefs := []v1alpha1.ObjectReference{
oldRef,
unusedRef,
}
index := NewObjectIndex(existingRefs, NewEquivalences(equis...))
newRef := v1alpha1.ObjectReference{
ObjectReference: corev1.ObjectReference{Name: "name", Namespace: "ns", Kind: "kindB", APIVersion: "groupB/v1"},
}
foundRef, found := index.Lookup(newRef)
Expect(found).To(BeTrue())
Expect(foundRef).To(Equal(oldRef))
Expect(index.Found(oldRef)).To(BeTrue())
Expect(index.Found(unusedRef)).To(BeFalse())
})
})
})