@@ -65,7 +65,7 @@ func newResource(name string, modifiers ...func(app *unstructured.Unstructured))
65
65
return & app
66
66
}
67
67
68
- func newController (t * testing.T , ctx context.Context , client dynamic.Interface , opts ... Opts ) (* notificationController , * mocks.MockAPI , error ) {
68
+ func newController (t * testing.T , ctx context.Context , client dynamic.Interface , factorySupport bool , opts ... Opts ) (* notificationController , * mocks.MockAPI , error ) {
69
69
mockCtrl := gomock .NewController (t )
70
70
go func () {
71
71
<- ctx .Done ()
@@ -90,7 +90,12 @@ func newController(t *testing.T, ctx context.Context, client dynamic.Interface,
90
90
91
91
go informer .Run (ctx .Done ())
92
92
93
- c := NewControllerWithNamespaceSupport (resourceClient , informer , & mocks.FakeFactory {Api : mockAPI }, opts ... )
93
+ var c * notificationController
94
+ if factorySupport {
95
+ c = NewControllerWithFactorySupport (resourceClient , informer , & mocks.FakeFactory {Api : mockAPI }, opts ... )
96
+ } else {
97
+ c = NewControllerWithNamespaceSupport (resourceClient , informer , & mocks.FakeFactory {Api : mockAPI }, opts ... )
98
+ }
94
99
if ! cache .WaitForCacheSync (ctx .Done (), informer .HasSynced ) {
95
100
return nil , nil , errors .New ("failed to sync informers" )
96
101
}
@@ -105,7 +110,7 @@ func TestSendsNotificationIfTriggered(t *testing.T) {
105
110
subscriptions .SubscribeAnnotationKey ("my-trigger" , "mock" ): "recipient" ,
106
111
}))
107
112
108
- ctrl , api , err := newController (t , ctx , newFakeClient (app ))
113
+ ctrl , api , err := newController (t , ctx , newFakeClient (app ), false )
109
114
assert .NoError (t , err )
110
115
111
116
receivedObj := map [string ]interface {}{}
@@ -136,7 +141,7 @@ func TestDoesNotSendNotificationIfAnnotationPresent(t *testing.T) {
136
141
subscriptions .SubscribeAnnotationKey ("my-trigger" , "mock" ): "recipient" ,
137
142
notifiedAnnotationKey : mustToJson (state ),
138
143
}))
139
- ctrl , api , err := newController (t , ctx , newFakeClient (app ))
144
+ ctrl , api , err := newController (t , ctx , newFakeClient (app ), false )
140
145
assert .NoError (t , err )
141
146
142
147
api .EXPECT ().RunTrigger ("my-trigger" , gomock .Any ()).Return ([]triggers.ConditionResult {{Triggered : true , Templates : []string {"test" }}}, nil )
@@ -158,7 +163,7 @@ func TestRemovesAnnotationIfNoTrigger(t *testing.T) {
158
163
subscriptions .SubscribeAnnotationKey ("my-trigger" , "mock" ): "recipient" ,
159
164
notifiedAnnotationKey : mustToJson (state ),
160
165
}))
161
- ctrl , api , err := newController (t , ctx , newFakeClient (app ))
166
+ ctrl , api , err := newController (t , ctx , newFakeClient (app ), false )
162
167
assert .NoError (t , err )
163
168
164
169
api .EXPECT ().RunTrigger ("my-trigger" , gomock .Any ()).Return ([]triggers.ConditionResult {{Triggered : false }}, nil )
@@ -173,6 +178,14 @@ func TestRemovesAnnotationIfNoTrigger(t *testing.T) {
173
178
}
174
179
175
180
func TestUpdatedAnnotationsSavedAsPatch (t * testing.T ) {
181
+ controllerRunAndVerifyResult (t , false )
182
+ }
183
+
184
+ func TestSendsNotificationUsingAPIFromFactory (t * testing.T ) {
185
+ controllerRunAndVerifyResult (t , true )
186
+ }
187
+
188
+ func controllerRunAndVerifyResult (t * testing.T , factorySupport bool ) {
176
189
ctx , cancel := context .WithCancel (context .TODO ())
177
190
defer cancel ()
178
191
@@ -191,7 +204,7 @@ func TestUpdatedAnnotationsSavedAsPatch(t *testing.T) {
191
204
patchCh <- action .(kubetesting.PatchAction ).GetPatch ()
192
205
return true , nil , nil
193
206
})
194
- ctrl , api , err := newController (t , ctx , client )
207
+ ctrl , api , err := newController (t , ctx , client , false )
195
208
assert .NoError (t , err )
196
209
api .EXPECT ().RunTrigger ("my-trigger" , gomock .Any ()).Return ([]triggers.ConditionResult {{Triggered : false }}, nil )
197
210
@@ -322,7 +335,7 @@ func TestWithEventCallback(t *testing.T) {
322
335
subscriptions .SubscribeAnnotationKey ("my-trigger" , "mock" ): "recipient" ,
323
336
}))
324
337
325
- ctrl , api , err := newController (t , ctx , newFakeClient (app ), WithEventCallback (mockEventCallback ))
338
+ ctrl , api , err := newController (t , ctx , newFakeClient (app ), false , WithEventCallback (mockEventCallback ))
326
339
ctrl .namespaceSupport = false
327
340
assert .NoError (t , err )
328
341
ctrl .apiFactory = & mocks.FakeFactory {Api : api , Err : tc .apiErr }
0 commit comments