@@ -140,6 +140,42 @@ func TestSkipWebSocket(t *testing.T) {
140140}
141141
142142func TestRunInformerToWatch (t * testing.T ) { //nolint: funlen
143+ grvlist := []schema.GroupVersionResource {
144+ {Group : "" , Version : "v1" , Resource : "pods" },
145+ {Group : "apps" , Version : "v1" , Resource : "deployments" },
146+ }
147+ clientMap := map [schema.GroupVersionResource ]string {
148+ {Group : "" , Version : "v1" , Resource : "pods" }: "PodList" ,
149+ {Group : "apps" , Version : "v1" , Resource : "deployments" }: "DeploymentList" ,
150+ }
151+ mockPod := & unstructured.Unstructured {
152+ Object : map [string ]interface {}{
153+ "apiVersion" : "v1" ,
154+ "kind" : "Pod" ,
155+ "metadata" : map [string ]interface {}{
156+ "name" : "test-pod" ,
157+ "namespace" : "default" ,
158+ "creationTimestamp" : time .Now ().UTC ().Format (time .RFC3339 ),
159+ },
160+ },
161+ }
162+ beforeCache := & MockCache {
163+ store : map [string ]string {
164+ "+pods+default+test-context-2" : "pod-data" ,
165+ "apps+deployments+default+test-context-2" : "deployment-data" ,
166+ "+nodes+default+test-context-2" : "node-data" ,
167+ "apps+replicaset+default+test-context-2" : "replicaset-data" ,
168+ },
169+ }
170+
171+ afterCache := & MockCache {
172+ store : map [string ]string {
173+ "apps+deployments+default+test-context-2" : "deployment-data" ,
174+ "+nodes+default+test-context-2" : "node-data" ,
175+ "apps+replicaset+default+test-context-2" : "replicaset-data" ,
176+ },
177+ }
178+
143179 tests := []struct {
144180 name string
145181 eventType string
@@ -151,121 +187,34 @@ func TestRunInformerToWatch(t *testing.T) { //nolint: funlen
151187 afterCache * MockCache
152188 }{
153189 {
154- name : "testing run watcher informer" ,
155- eventType : "add" ,
156- contextKey : "test-context-add" ,
157- gvrList : []schema.GroupVersionResource {
158- {Group : "" , Version : "v1" , Resource : "pods" },
159- {Group : "apps" , Version : "v1" , Resource : "deployments" },
160- },
161- clientMap : map [schema.GroupVersionResource ]string {
162- {Group : "" , Version : "v1" , Resource : "pods" }: "PodList" ,
163- {Group : "apps" , Version : "v1" , Resource : "deployments" }: "DeploymentList" ,
164- },
165- mockPod : & unstructured.Unstructured {
166- Object : map [string ]interface {}{
167- "apiVersion" : "v1" ,
168- "kind" : "Pod" ,
169- "metadata" : map [string ]interface {}{
170- "name" : "test-pod-add" ,
171- "namespace" : "default" ,
172- "creationTimestamp" : time .Now ().UTC ().Format (time .RFC3339 ),
173- },
174- },
175- },
176- beforeCache : & MockCache {
177- store : map [string ]string {
178- "+pods+default+test-context-add" : "pod-data-add" ,
179- "apps+deployments+default+test-context-add" : "deployment-data-add" ,
180- "+nodes+default+test-context-add" : "node-data-add" ,
181- "apps+replicaset+default+test-context-add" : "replicaset-data-add" ,
182- },
183- },
184- afterCache : & MockCache {
185- store : map [string ]string {
186- "apps+deployments+default+test-context-add" : "deployment-data-add" ,
187- "+nodes+default+test-context-add" : "node-data-add" ,
188- "apps+replicaset+default+test-context-add" : "replicaset-data-add" ,
189- },
190- },
190+ name : "testing run watcher informer" ,
191+ eventType : "add" ,
192+ contextKey : "test-context-2" ,
193+ gvrList : grvlist ,
194+ clientMap : clientMap ,
195+ mockPod : mockPod ,
196+ beforeCache : beforeCache ,
197+ afterCache : afterCache ,
191198 },
192199 {
193- name : "invalidate cache on update event" ,
194- eventType : "update" ,
195- contextKey : "test-context-update" ,
196- gvrList : []schema.GroupVersionResource {
197- {Group : "" , Version : "v1" , Resource : "pods" },
198- {Group : "apps" , Version : "v1" , Resource : "deployments" },
199- },
200- clientMap : map [schema.GroupVersionResource ]string {
201- {Group : "" , Version : "v1" , Resource : "pods" }: "PodList" ,
202- {Group : "apps" , Version : "v1" , Resource : "deployments" }: "DeploymentList" ,
203- },
204- mockPod : & unstructured.Unstructured {
205- Object : map [string ]interface {}{
206- "apiVersion" : "v1" ,
207- "kind" : "Pod" ,
208- "metadata" : map [string ]interface {}{
209- "name" : "test-pod-update" ,
210- "namespace" : "default" ,
211- "creationTimestamp" : time .Now ().UTC ().Format (time .RFC3339 ),
212- },
213- },
214- },
215- beforeCache : & MockCache {
216- store : map [string ]string {
217- "+pods+default+test-context-update" : "pod-data-update" ,
218- "apps+deployments+default+test-context-update" : "deployment-data-update" ,
219- "+nodes+default+test-context-update" : "node-data-update" ,
220- "apps+replicaset+default+test-context-update" : "replicaset-data-update" ,
221- },
222- },
223- afterCache : & MockCache {
224- store : map [string ]string {
225- "apps+deployments+default+test-context-update" : "deployment-data-update" ,
226- "+nodes+default+test-context-update" : "node-data-update" ,
227- "apps+replicaset+default+test-context-update" : "replicaset-data-update" ,
228- },
229- },
200+ name : "testing run watcher informer for update event" ,
201+ eventType : "update" ,
202+ contextKey : "test-context-2" ,
203+ gvrList : grvlist ,
204+ clientMap : clientMap ,
205+ mockPod : mockPod ,
206+ beforeCache : beforeCache ,
207+ afterCache : afterCache ,
230208 },
231209 {
232- name : "invalidate cache on delete event" ,
233- eventType : "delete" ,
234- contextKey : "test-context-delete" ,
235- gvrList : []schema.GroupVersionResource {
236- {Group : "" , Version : "v1" , Resource : "pods" },
237- {Group : "apps" , Version : "v1" , Resource : "deployments" },
238- },
239- clientMap : map [schema.GroupVersionResource ]string {
240- {Group : "" , Version : "v1" , Resource : "pods" }: "PodList" ,
241- {Group : "apps" , Version : "v1" , Resource : "deployments" }: "DeploymentList" ,
242- },
243- mockPod : & unstructured.Unstructured {
244- Object : map [string ]interface {}{
245- "apiVersion" : "v1" ,
246- "kind" : "Pod" ,
247- "metadata" : map [string ]interface {}{
248- "name" : "test-pod-delete" ,
249- "namespace" : "default" ,
250- "creationTimestamp" : time .Now ().UTC ().Format (time .RFC3339 ),
251- },
252- },
253- },
254- beforeCache : & MockCache {
255- store : map [string ]string {
256- "+pods+default+test-context-delete" : "pod-data-delete" ,
257- "apps+deployments+default+test-context-delete" : "deployment-data-delete" ,
258- "+nodes+default+test-context-delete" : "node-data-delete" ,
259- "apps+replicaset+default+test-context-delete" : "replicaset-data-delete" ,
260- },
261- },
262- afterCache : & MockCache {
263- store : map [string ]string {
264- "apps+deployments+default+test-context-delete" : "deployment-data-delete" ,
265- "+nodes+default+test-context-delete" : "node-data-delete" ,
266- "apps+replicaset+default+test-context-delete" : "replicaset-data-delete" ,
267- },
268- },
210+ name : "testing run watcher informer for delete event" ,
211+ eventType : "delete" ,
212+ contextKey : "test-context-2" ,
213+ gvrList : grvlist ,
214+ clientMap : clientMap ,
215+ mockPod : mockPod ,
216+ beforeCache : beforeCache ,
217+ afterCache : afterCache ,
269218 },
270219 }
271220
0 commit comments