@@ -37,6 +37,25 @@ import (
37
37
"sigs.k8s.io/controller-runtime/pkg/kontext"
38
38
)
39
39
40
+ func newPublishedResources (relatedResources []syncagentv1alpha1.RelatedResourceSpec ) * syncagentv1alpha1.PublishedResource {
41
+ return & syncagentv1alpha1.PublishedResource {
42
+ Spec : syncagentv1alpha1.PublishedResourceSpec {
43
+ Resource : syncagentv1alpha1.SourceResourceDescriptor {
44
+ APIGroup : dummyv1alpha1 .GroupName ,
45
+ Version : dummyv1alpha1 .GroupVersion ,
46
+ Kind : "NamespacedThing" ,
47
+ },
48
+ Projection : & syncagentv1alpha1.ResourceProjection {
49
+ Kind : "RemoteThing" ,
50
+ },
51
+ Naming : & syncagentv1alpha1.ResourceNaming {
52
+ Name : "$remoteClusterName-$remoteName" ,
53
+ },
54
+ Related : relatedResources ,
55
+ },
56
+ }
57
+ }
58
+
40
59
func TestSyncerProcessingRelatedResources (t * testing.T ) {
41
60
const stateNamespace = "kcp-system"
42
61
@@ -57,34 +76,12 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
57
76
58
77
clusterName := logicalcluster .Name ("testcluster" )
59
78
60
- remoteThingPR := & syncagentv1alpha1.PublishedResource {
61
- Spec : syncagentv1alpha1.PublishedResourceSpec {
62
- Resource : syncagentv1alpha1.SourceResourceDescriptor {
63
- APIGroup : dummyv1alpha1 .GroupName ,
64
- Version : dummyv1alpha1 .GroupVersion ,
65
- Kind : "NamespacedThing" ,
66
- },
67
- Projection : & syncagentv1alpha1.ResourceProjection {
68
- Kind : "RemoteThing" ,
69
- },
70
- // include explicit naming rules to be independent of possible changes to the defaults
71
- Naming : & syncagentv1alpha1.ResourceNaming {
72
- Name : "$remoteClusterName-$remoteName" , // Things are Cluster-scoped
73
- },
74
- Related : []syncagentv1alpha1.RelatedResourceSpec {
75
- {
76
- Identifier : "mandatory-credentials" ,
77
- Origin : "kcp" ,
78
- Kind : "Secret" ,
79
- Reference : syncagentv1alpha1.RelatedResourceReference {
80
- Name : syncagentv1alpha1.ResourceLocator {
81
- Path : "metadata.name" ,
82
- Regex : & syncagentv1alpha1.RegexResourceLocator {
83
- Replacement : "mandatory-credentials" ,
84
- },
85
- },
86
- },
87
- },
79
+ testcases := []testcase {
80
+ {
81
+ name : "optional related resource does not exist" ,
82
+ remoteAPIGroup : "remote.example.corp" ,
83
+ localCRD : loadCRD ("things" ),
84
+ pubRes : newPublishedResources ([]syncagentv1alpha1.RelatedResourceSpec {
88
85
{
89
86
Identifier : "optional-secret" ,
90
87
Origin : "service" ,
@@ -97,20 +94,9 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
97
94
},
98
95
},
99
96
},
100
- Optional : true ,
101
97
},
102
- },
103
- },
104
- }
105
-
106
- testcases := []testcase {
107
- {
108
- name : "optional related resource does not exist" ,
109
- remoteAPIGroup : "remote.example.corp" ,
110
- localCRD : loadCRD ("things" ),
111
- pubRes : remoteThingPR ,
98
+ }),
112
99
performRequeues : true ,
113
-
114
100
remoteObject : newUnstructured (& dummyv1alpha1.NamespacedThing {
115
101
ObjectMeta : metav1.ObjectMeta {
116
102
Name : "my-test-thing" ,
@@ -173,12 +159,25 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
173
159
expectedState : `{"apiVersion":"remote.example.corp/v1alpha1","kind":"RemoteThing","metadata":{"name":"my-test-thing","namespace":"kcp-system"},"spec":{"username":"Colonel Mustard"}}` ,
174
160
},
175
161
{
176
- name : "mandatory related resource does not exist" ,
177
- remoteAPIGroup : "remote.example.corp" ,
178
- localCRD : loadCRD ("things" ),
179
- pubRes : remoteThingPR ,
162
+ name : "mandatory related resource does not exist" ,
163
+ remoteAPIGroup : "remote.example.corp" ,
164
+ localCRD : loadCRD ("things" ),
165
+ pubRes : newPublishedResources ([]syncagentv1alpha1.RelatedResourceSpec {
166
+ {
167
+ Identifier : "mandatory-credentials" ,
168
+ Origin : "kcp" ,
169
+ Kind : "Secret" ,
170
+ Reference : syncagentv1alpha1.RelatedResourceReference {
171
+ Name : syncagentv1alpha1.ResourceLocator {
172
+ Path : "metadata.name" ,
173
+ Regex : & syncagentv1alpha1.RegexResourceLocator {
174
+ Replacement : "mandatory-credentials" ,
175
+ },
176
+ },
177
+ },
178
+ },
179
+ }),
180
180
performRequeues : true ,
181
-
182
181
remoteObject : newUnstructured (& dummyv1alpha1.NamespacedThing {
183
182
ObjectMeta : metav1.ObjectMeta {
184
183
Name : "my-test-thing" ,
0 commit comments