@@ -5,11 +5,15 @@ import (
5
5
. "github.com/onsi/ginkgo/extensions/table"
6
6
. "github.com/onsi/gomega"
7
7
"github.com/redhat-developer/service-binding-operator/api/v1alpha1"
8
+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8
9
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
9
10
"k8s.io/apimachinery/pkg/runtime"
10
11
"k8s.io/apimachinery/pkg/runtime/schema"
12
+ "k8s.io/apimachinery/pkg/types"
13
+ "k8s.io/apimachinery/pkg/util/uuid"
11
14
"k8s.io/client-go/dynamic"
12
15
"k8s.io/client-go/dynamic/fake"
16
+ "strings"
13
17
)
14
18
15
19
var _ = Describe ("Service" , func () {
@@ -43,8 +47,55 @@ var _ = Describe("Service", func() {
43
47
Expect (res ).To (BeNil ())
44
48
})
45
49
50
+ It ("should return owned resources" , func () {
51
+ var objs []runtime.Object
52
+ id := uuid .NewUUID ()
53
+ id2 := uuid .NewUUID ()
54
+ ns := "ns1"
55
+ u := & unstructured.Unstructured {}
56
+ u .SetGroupVersionKind (schema.GroupVersionKind {Group : "foo.bar" , Version : "v1" , Kind : "Foo" })
57
+ u .SetName ("foo" )
58
+ u .SetNamespace (ns )
59
+ u .SetUID (id )
60
+
61
+ objs = append (objs , u )
62
+
63
+ var children []interface {}
64
+
65
+ for _ , gvr := range bindableResourceGVRs {
66
+ gvk := gvr .GroupVersion ().WithKind (strings .Title (gvr .Resource )[:len (gvr .Resource )- 1 ])
67
+ ou := resource (gvk , "child1" , ns , id )
68
+
69
+ ou2 := resource (gvk , "child2" , ns , id2 )
70
+
71
+ children = append (children , ou )
72
+ objs = append (objs , ou , ou2 )
73
+ }
74
+
75
+ client = fake .NewSimpleDynamicClient (runtime .NewScheme (), objs ... )
76
+
77
+ impl := & service {client : client , resource : u , lookForOwnedResources : true , serviceRef : & v1alpha1.Service { NamespacedRef : v1alpha1.NamespacedRef {Namespace : & ns }}}
78
+
79
+ ownedResources , err := impl .OwnedResources ()
80
+ Expect (err ).NotTo (HaveOccurred ())
81
+ Expect (ownedResources ).Should (HaveLen (len (bindableResourceGVRs )))
82
+ Expect (ownedResources ).Should (ContainElements (children ... ))
83
+ })
46
84
})
47
85
86
+ func resource (gvk schema.GroupVersionKind , name string , namespace string , owner types.UID ) * unstructured.Unstructured {
87
+ u := & unstructured.Unstructured {}
88
+ u .SetGroupVersionKind (gvk )
89
+ u .SetName (name )
90
+ u .SetNamespace (namespace )
91
+ u .SetOwnerReferences ([]v1.OwnerReference {
92
+ {
93
+ UID : owner ,
94
+ },
95
+ })
96
+ return u
97
+ }
98
+
48
99
func crd (version string , gr schema.GroupResource ) * unstructured.Unstructured {
49
100
u := & unstructured.Unstructured {}
50
101
u .SetGroupVersionKind (schema.GroupVersionKind {Group : "apiextensions.k8s.io" , Version : version , Kind : "CustomResourceDefinition" })
0 commit comments