@@ -37,6 +37,25 @@ import (
3737 "sigs.k8s.io/controller-runtime/pkg/kontext"
3838)
3939
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+
4059func TestSyncerProcessingRelatedResources (t * testing.T ) {
4160 const stateNamespace = "kcp-system"
4261
@@ -57,34 +76,12 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
5776
5877 clusterName := logicalcluster .Name ("testcluster" )
5978
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 {
8885 {
8986 Identifier : "optional-secret" ,
9087 Origin : "service" ,
@@ -97,20 +94,9 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
9794 },
9895 },
9996 },
100- Optional : true ,
10197 },
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+ }),
11299 performRequeues : true ,
113-
114100 remoteObject : newUnstructured (& dummyv1alpha1.NamespacedThing {
115101 ObjectMeta : metav1.ObjectMeta {
116102 Name : "my-test-thing" ,
@@ -173,12 +159,25 @@ func TestSyncerProcessingRelatedResources(t *testing.T) {
173159 expectedState : `{"apiVersion":"remote.example.corp/v1alpha1","kind":"RemoteThing","metadata":{"name":"my-test-thing","namespace":"kcp-system"},"spec":{"username":"Colonel Mustard"}}` ,
174160 },
175161 {
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+ }),
180180 performRequeues : true ,
181-
182181 remoteObject : newUnstructured (& dummyv1alpha1.NamespacedThing {
183182 ObjectMeta : metav1.ObjectMeta {
184183 Name : "my-test-thing" ,
0 commit comments