@@ -82,7 +82,7 @@ func TestNewProxyStore(t *testing.T) {
82
82
nsSchema := baseNSSchema
83
83
scc .EXPECT ().SetColumns (context .Background (), & nsSchema ).Return (nil )
84
84
cg .EXPECT ().TableAdminClient (nil , & nsSchema , "" , & WarningBuffer {}).Return (ri , nil )
85
- cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false ).Return (c , nil )
85
+ cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false , true ).Return (c , nil )
86
86
87
87
s , err := NewProxyStore (scc , cg , rn , nil , cf )
88
88
assert .Nil (t , err )
@@ -149,7 +149,7 @@ func TestNewProxyStore(t *testing.T) {
149
149
nsSchema := baseNSSchema
150
150
scc .EXPECT ().SetColumns (context .Background (), & nsSchema ).Return (nil )
151
151
cg .EXPECT ().TableAdminClient (nil , & nsSchema , "" , & WarningBuffer {}).Return (ri , nil )
152
- cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false ).Return (factory.Cache {}, fmt .Errorf ("error" ))
152
+ cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false , true ).Return (factory.Cache {}, fmt .Errorf ("error" ))
153
153
154
154
s , err := NewProxyStore (scc , cg , rn , nil , cf )
155
155
assert .Nil (t , err )
@@ -207,6 +207,7 @@ func TestListByPartitions(t *testing.T) {
207
207
Field : "some.field" ,
208
208
},
209
209
},
210
+ "verbs" : []string {"list" , "watch" },
210
211
}},
211
212
}
212
213
expectedItems := []unstructured.Unstructured {
@@ -240,7 +241,7 @@ func TestListByPartitions(t *testing.T) {
240
241
assert .Nil (t , err )
241
242
cg .EXPECT ().TableAdminClient (req , schema , "" , & WarningBuffer {}).Return (ri , nil )
242
243
// This tests that fields are being extracted from schema columns and the type specific fields map
243
- cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema )).Return (c , nil )
244
+ cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema ), true ).Return (c , nil )
244
245
tb .EXPECT ().GetTransformFunc (attributes .GVK (schema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
245
246
bloi .EXPECT ().ListByOptions (req .Context (), opts , partitions , req .Namespace ).Return (listToReturn , len (listToReturn .Items ), "" , nil )
246
247
list , total , contToken , err := s .ListByPartitions (req , schema , partitions )
@@ -277,6 +278,7 @@ func TestListByPartitions(t *testing.T) {
277
278
Field : "some.field" ,
278
279
},
279
280
},
281
+ "verbs" : []string {"list" , "watch" },
280
282
}},
281
283
}
282
284
expectedItems := []unstructured.Unstructured {
@@ -343,6 +345,7 @@ func TestListByPartitions(t *testing.T) {
343
345
Field : "some.field" ,
344
346
},
345
347
},
348
+ "verbs" : []string {"list" , "watch" },
346
349
}},
347
350
}
348
351
expectedItems := []unstructured.Unstructured {
@@ -380,6 +383,88 @@ func TestListByPartitions(t *testing.T) {
380
383
assert .NotNil (t , err )
381
384
},
382
385
})
386
+ tests = append (tests , testCase {
387
+ description : "client ListByPartitions() should detect listable-but-unwatchable schema, still work normally" ,
388
+ test : func (t * testing.T ) {
389
+ nsi := NewMockCache (gomock .NewController (t ))
390
+ cg := NewMockClientGetter (gomock .NewController (t ))
391
+ cf := NewMockCacheFactory (gomock .NewController (t ))
392
+ ri := NewMockResourceInterface (gomock .NewController (t ))
393
+ bloi := NewMockByOptionsLister (gomock .NewController (t ))
394
+ tb := NewMockTransformBuilder (gomock .NewController (t ))
395
+ inf := & informer.Informer {
396
+ ByOptionsLister : bloi ,
397
+ }
398
+ c := factory.Cache {
399
+ ByOptionsLister : inf ,
400
+ }
401
+ s := & Store {
402
+ namespaceCache : nsi ,
403
+ clientGetter : cg ,
404
+ cacheFactory : cf ,
405
+ transformBuilder : tb ,
406
+ }
407
+ var partitions []partition.Partition
408
+ req := & types.APIRequest {
409
+ Request : & http.Request {
410
+ URL : & url.URL {},
411
+ },
412
+ }
413
+ schema := & types.APISchema {
414
+ Schema : & schemas.Schema {Attributes : map [string ]interface {}{
415
+ "columns" : []common.ColumnDefinition {
416
+ {
417
+ Field : "some.field" ,
418
+ },
419
+ },
420
+ // note: no watch here
421
+ "verbs" : []string {"list" },
422
+ }},
423
+ }
424
+ expectedItems := []unstructured.Unstructured {
425
+ {
426
+ Object : map [string ]interface {}{
427
+ "kind" : "apple" ,
428
+ "metadata" : map [string ]interface {}{
429
+ "name" : "fuji" ,
430
+ },
431
+ "data" : map [string ]interface {}{
432
+ "color" : "pink" ,
433
+ },
434
+ },
435
+ },
436
+ }
437
+ listToReturn := & unstructured.UnstructuredList {
438
+ Items : make ([]unstructured.Unstructured , len (expectedItems ), len (expectedItems )),
439
+ }
440
+ gvk := schema2.GroupVersionKind {
441
+ Group : "some" ,
442
+ Version : "test" ,
443
+ Kind : "gvk" ,
444
+ }
445
+ typeSpecificIndexedFields ["some_test_gvk" ] = [][]string {{"gvk" , "specific" , "fields" }}
446
+
447
+ attributes .SetGVK (schema , gvk )
448
+ // ListByPartitions copies point so we need some original record of items to ensure as asserting listToReturn's
449
+ // items is equal to the list returned by ListByParititons doesn't ensure no mutation happened
450
+ copy (listToReturn .Items , expectedItems )
451
+ opts , err := listprocessor .ParseQuery (req , nil )
452
+ assert .Nil (t , err )
453
+ cg .EXPECT ().TableAdminClient (req , schema , "" , & WarningBuffer {}).Return (ri , nil )
454
+
455
+ // This tests that fields are being extracted from schema columns and the type specific fields map
456
+ // note also the watchable bool is expected to be false
457
+ cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema ), false ).Return (c , nil )
458
+
459
+ tb .EXPECT ().GetTransformFunc (attributes .GVK (schema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
460
+ bloi .EXPECT ().ListByOptions (req .Context (), opts , partitions , req .Namespace ).Return (listToReturn , len (listToReturn .Items ), "" , nil )
461
+ list , total , contToken , err := s .ListByPartitions (req , schema , partitions )
462
+ assert .Nil (t , err )
463
+ assert .Equal (t , expectedItems , list )
464
+ assert .Equal (t , len (expectedItems ), total )
465
+ assert .Equal (t , "" , contToken )
466
+ },
467
+ })
383
468
tests = append (tests , testCase {
384
469
description : "client ListByPartitions() with CacheFor() error returned should returned an errors. Should pass fields" ,
385
470
test : func (t * testing.T ) {
@@ -408,6 +493,7 @@ func TestListByPartitions(t *testing.T) {
408
493
Field : "some.field" ,
409
494
},
410
495
},
496
+ "verbs" : []string {"list" , "watch" },
411
497
}},
412
498
}
413
499
expectedItems := []unstructured.Unstructured {
@@ -442,7 +528,7 @@ func TestListByPartitions(t *testing.T) {
442
528
cg .EXPECT ().TableAdminClient (req , schema , "" , & WarningBuffer {}).Return (ri , nil )
443
529
// This tests that fields are being extracted from schema columns and the type specific fields map
444
530
tb .EXPECT ().GetTransformFunc (attributes .GVK (schema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
445
- cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema )).Return (factory.Cache {}, fmt .Errorf ("error" ))
531
+ cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema ), true ).Return (factory.Cache {}, fmt .Errorf ("error" ))
446
532
447
533
_ , _ , _ , err = s .ListByPartitions (req , schema , partitions )
448
534
assert .NotNil (t , err )
@@ -483,6 +569,7 @@ func TestListByPartitions(t *testing.T) {
483
569
Field : "some.field" ,
484
570
},
485
571
},
572
+ "verbs" : []string {"list" , "watch" },
486
573
}},
487
574
}
488
575
expectedItems := []unstructured.Unstructured {
@@ -516,7 +603,7 @@ func TestListByPartitions(t *testing.T) {
516
603
assert .Nil (t , err )
517
604
cg .EXPECT ().TableAdminClient (req , schema , "" , & WarningBuffer {}).Return (ri , nil )
518
605
// This tests that fields are being extracted from schema columns and the type specific fields map
519
- cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema )).Return (c , nil )
606
+ cf .EXPECT ().CacheFor ([][]string {{"some" , "field" }, {`id` }, {`metadata` , `state` , `name` }, {"gvk" , "specific" , "fields" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (schema ), attributes .Namespaced (schema ), true ).Return (c , nil )
520
607
bloi .EXPECT ().ListByOptions (req .Context (), opts , partitions , req .Namespace ).Return (nil , 0 , "" , fmt .Errorf ("error" ))
521
608
tb .EXPECT ().GetTransformFunc (attributes .GVK (schema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
522
609
@@ -558,7 +645,7 @@ func TestReset(t *testing.T) {
558
645
cf .EXPECT ().Reset ().Return (nil )
559
646
cs .EXPECT ().SetColumns (gomock .Any (), gomock .Any ()).Return (nil )
560
647
cg .EXPECT ().TableAdminClient (nil , & nsSchema , "" , & WarningBuffer {}).Return (ri , nil )
561
- cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false ).Return (nsc2 , nil )
648
+ cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false , true ).Return (nsc2 , nil )
562
649
tb .EXPECT ().GetTransformFunc (attributes .GVK (& nsSchema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
563
650
err := s .Reset ()
564
651
assert .Nil (t , err )
@@ -661,7 +748,7 @@ func TestReset(t *testing.T) {
661
748
cf .EXPECT ().Reset ().Return (nil )
662
749
cs .EXPECT ().SetColumns (gomock .Any (), gomock .Any ()).Return (nil )
663
750
cg .EXPECT ().TableAdminClient (nil , & nsSchema , "" , & WarningBuffer {}).Return (ri , nil )
664
- cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false ).Return (factory.Cache {}, fmt .Errorf ("error" ))
751
+ cf .EXPECT ().CacheFor ([][]string {{`id` }, {`metadata` , `state` , `name` }, {"metadata" , "labels[field.cattle.io/projectId]" }}, gomock .Any (), & tablelistconvert.Client {ResourceInterface : ri }, attributes .GVK (& nsSchema ), false , true ).Return (factory.Cache {}, fmt .Errorf ("error" ))
665
752
tb .EXPECT ().GetTransformFunc (attributes .GVK (& nsSchema )).Return (func (obj interface {}) (interface {}, error ) { return obj , nil })
666
753
err := s .Reset ()
667
754
assert .NotNil (t , err )
0 commit comments