@@ -52,7 +52,7 @@ const (
52
52
// startServer creates a gRPC server without any registered services.
53
53
// The returned address can be used to connect to it. The cleanup
54
54
// function stops it. It can be called multiple times.
55
- func startServer (t * testing.T , tmp string , identity csi.IdentityServer , controller csi.ControllerServer ) (string , func ()) {
55
+ func startServer (t * testing.T , tmp string , identity csi.IdentityServer , controller csi.ControllerServer , groupCtrl csi. GroupControllerServer ) (string , func ()) {
56
56
addr := path .Join (tmp , serverSock )
57
57
listener , err := net .Listen ("unix" , addr )
58
58
require .NoError (t , err , "listening on %s" , addr )
@@ -63,6 +63,9 @@ func startServer(t *testing.T, tmp string, identity csi.IdentityServer, controll
63
63
if controller != nil {
64
64
csi .RegisterControllerServer (server , controller )
65
65
}
66
+ if groupCtrl != nil {
67
+ csi .RegisterGroupControllerServer (server , groupCtrl )
68
+ }
66
69
var wg sync.WaitGroup
67
70
wg .Add (1 )
68
71
go func () {
@@ -127,7 +130,7 @@ func TestGetDriverName(t *testing.T) {
127
130
pluginInfoResponse : out ,
128
131
err : injectedErr ,
129
132
}
130
- addr , stopServer := startServer (t , tmp , identity , nil )
133
+ addr , stopServer := startServer (t , tmp , identity , nil , nil )
131
134
defer func () {
132
135
stopServer ()
133
136
}()
@@ -247,7 +250,7 @@ func TestGetPluginCapabilities(t *testing.T) {
247
250
// and 1.11.1 (which will be used by new Prow job) via an extra blank line.
248
251
err : injectedErr ,
249
252
}
250
- addr , stopServer := startServer (t , tmp , identity , nil )
253
+ addr , stopServer := startServer (t , tmp , identity , nil , nil )
251
254
defer func () {
252
255
stopServer ()
253
256
}()
@@ -375,7 +378,7 @@ func TestGetControllerCapabilities(t *testing.T) {
375
378
// and 1.11.1 (which will be used by new Prow job) via an extra blank line.
376
379
err : injectedErr ,
377
380
}
378
- addr , stopServer := startServer (t , tmp , nil , controller )
381
+ addr , stopServer := startServer (t , tmp , nil , controller , nil )
379
382
defer func () {
380
383
stopServer ()
381
384
}()
@@ -399,6 +402,100 @@ func TestGetControllerCapabilities(t *testing.T) {
399
402
}
400
403
}
401
404
405
+ func TestGetGroupControllerCapabilities (t * testing.T ) {
406
+ tests := []struct {
407
+ name string
408
+ output * csi.GroupControllerGetCapabilitiesResponse
409
+ injectError bool
410
+ expectCapabilities GroupControllerCapabilitySet
411
+ expectError bool
412
+ }{
413
+ {
414
+ name : "success" ,
415
+ output : & csi.GroupControllerGetCapabilitiesResponse {
416
+ Capabilities : []* csi.GroupControllerServiceCapability {
417
+ {
418
+ Type : & csi.GroupControllerServiceCapability_Rpc {
419
+ Rpc : & csi.GroupControllerServiceCapability_RPC {
420
+ Type : csi .GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT ,
421
+ },
422
+ },
423
+ },
424
+ },
425
+ },
426
+ expectCapabilities : GroupControllerCapabilitySet {
427
+ csi .GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT : true ,
428
+ },
429
+ expectError : false ,
430
+ },
431
+ {
432
+ name : "gRPC error" ,
433
+ output : nil ,
434
+ injectError : true ,
435
+ expectError : true ,
436
+ },
437
+ {
438
+ name : "empty capability" ,
439
+ output : & csi.GroupControllerGetCapabilitiesResponse {
440
+ Capabilities : []* csi.GroupControllerServiceCapability {
441
+ {
442
+ Type : nil ,
443
+ },
444
+ },
445
+ },
446
+ expectCapabilities : GroupControllerCapabilitySet {},
447
+ expectError : false ,
448
+ },
449
+ {
450
+ name : "no capabilities" ,
451
+ output : & csi.GroupControllerGetCapabilitiesResponse {
452
+ Capabilities : []* csi.GroupControllerServiceCapability {},
453
+ },
454
+ expectCapabilities : GroupControllerCapabilitySet {},
455
+ expectError : false ,
456
+ },
457
+ }
458
+
459
+ for _ , test := range tests {
460
+ t .Run (test .name , func (t * testing.T ) {
461
+ var injectedErr error
462
+ if test .injectError {
463
+ injectedErr = fmt .Errorf ("mock error" )
464
+ }
465
+
466
+ tmp := tmpDir (t )
467
+ defer os .RemoveAll (tmp )
468
+ groupCtrl := & fakeGroupControllerServer {
469
+ groupControllerGetCapabilitiesResponse : test .output ,
470
+
471
+ // Make code compatible with gofmt 1.10.2 (used by pull-sig-storage-csi-lib-utils-stable)
472
+ // and 1.11.1 (which will be used by new Prow job) via an extra blank line.
473
+ err : injectedErr ,
474
+ }
475
+ addr , stopServer := startServer (t , tmp , nil , nil , groupCtrl )
476
+ defer func () {
477
+ stopServer ()
478
+ }()
479
+
480
+ conn , err := connection .Connect (addr , metrics .NewCSIMetricsManager ("fake.csi.driver.io" ))
481
+ if err != nil {
482
+ t .Fatalf ("Failed to connect to CSI driver: %s" , err )
483
+ }
484
+
485
+ caps , err := GetGroupControllerCapabilities (context .Background (), conn )
486
+ if test .expectError && err == nil {
487
+ t .Errorf ("Expected error, got none" )
488
+ }
489
+ if ! test .expectError && err != nil {
490
+ t .Errorf ("Got error: %v" , err )
491
+ }
492
+ if ! reflect .DeepEqual (test .expectCapabilities , caps ) {
493
+ t .Errorf ("expected capabilities %+v, got %+v" , test .expectCapabilities , caps )
494
+ }
495
+ })
496
+ }
497
+ }
498
+
402
499
func TestProbeForever (t * testing.T ) {
403
500
tests := []struct {
404
501
name string
@@ -509,7 +606,7 @@ func TestProbeForever(t *testing.T) {
509
606
identity := & fakeIdentityServer {
510
607
probeCalls : test .probeCalls ,
511
608
}
512
- addr , stopServer := startServer (t , tmp , identity , nil )
609
+ addr , stopServer := startServer (t , tmp , identity , nil , nil )
513
610
defer func () {
514
611
stopServer ()
515
612
}()
@@ -624,3 +721,26 @@ func (c *fakeControllerServer) ListSnapshots(context.Context, *csi.ListSnapshots
624
721
func (c * fakeControllerServer ) ControllerExpandVolume (context.Context , * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
625
722
return nil , fmt .Errorf ("unimplemented" )
626
723
}
724
+
725
+ type fakeGroupControllerServer struct {
726
+ groupControllerGetCapabilitiesResponse * csi.GroupControllerGetCapabilitiesResponse
727
+ err error
728
+ }
729
+
730
+ var _ csi.GroupControllerServer = & fakeGroupControllerServer {}
731
+
732
+ func (c * fakeGroupControllerServer ) GroupControllerGetCapabilities (context.Context , * csi.GroupControllerGetCapabilitiesRequest ) (* csi.GroupControllerGetCapabilitiesResponse , error ) {
733
+ return c .groupControllerGetCapabilitiesResponse , c .err
734
+ }
735
+
736
+ func (c * fakeGroupControllerServer ) CreateVolumeGroupSnapshot (context.Context , * csi.CreateVolumeGroupSnapshotRequest ) (* csi.CreateVolumeGroupSnapshotResponse , error ) {
737
+ return nil , fmt .Errorf ("unimplemented" )
738
+ }
739
+
740
+ func (c * fakeGroupControllerServer ) DeleteVolumeGroupSnapshot (context.Context , * csi.DeleteVolumeGroupSnapshotRequest ) (* csi.DeleteVolumeGroupSnapshotResponse , error ) {
741
+ return nil , fmt .Errorf ("unimplemented" )
742
+ }
743
+
744
+ func (c * fakeGroupControllerServer ) GetVolumeGroupSnapshot (context.Context , * csi.GetVolumeGroupSnapshotRequest ) (* csi.GetVolumeGroupSnapshotResponse , error ) {
745
+ return nil , fmt .Errorf ("unimplemented" )
746
+ }
0 commit comments