@@ -18,7 +18,7 @@ package driver
18
18
19
19
import (
20
20
"errors"
21
- "os "
21
+ "fmt "
22
22
"reflect"
23
23
"testing"
24
24
@@ -618,6 +618,7 @@ func TestNodeGetInfo(t *testing.T) {
618
618
testCases := []struct {
619
619
testCaseName string
620
620
driverStatsUtils utils.StatsUtils
621
+ envVars map [string ]string
621
622
req * csi.NodeGetInfoRequest
622
623
expectedResp * csi.NodeGetInfoResponse
623
624
expectedErr error
@@ -630,6 +631,9 @@ func TestNodeGetInfo(t *testing.T) {
630
631
return "test-region" , "test-zone" , nil
631
632
},
632
633
}),
634
+ envVars : map [string ]string {
635
+ "KUBE_NODE_NAME" : "testNode" ,
636
+ },
633
637
expectedResp : & csi.NodeGetInfoResponse {
634
638
NodeId : testNodeID ,
635
639
MaxVolumesPerNode : constants .DefaultVolumesPerNode ,
@@ -642,12 +646,53 @@ func TestNodeGetInfo(t *testing.T) {
642
646
},
643
647
expectedErr : nil ,
644
648
},
649
+ {
650
+ testCaseName : "Positive: Custom max volumes per node" ,
651
+ req : & csi.NodeGetInfoRequest {},
652
+ driverStatsUtils : utils .NewFakeStatsUtilsImpl (utils.FakeStatsUtilsFuncStruct {
653
+ GetRegionAndZoneFn : func (nodeName string ) (string , string , error ) {
654
+ return "test-region" , "test-zone" , nil
655
+ },
656
+ }),
657
+ envVars : map [string ]string {
658
+ "KUBE_NODE_NAME" : "testNode" ,
659
+ "MAX_VOLUMES_PER_NODE" : "4" ,
660
+ },
661
+ expectedResp : & csi.NodeGetInfoResponse {
662
+ NodeId : testNodeID ,
663
+ MaxVolumesPerNode : 4 ,
664
+ AccessibleTopology : & csi.Topology {
665
+ Segments : map [string ]string {
666
+ constants .NodeRegionLabel : "test-region" ,
667
+ constants .NodeZoneLabel : "test-zone" ,
668
+ },
669
+ },
670
+ },
671
+ expectedErr : nil ,
672
+ },
673
+ {
674
+ testCaseName : "Negative: invalid custom max volumes per node" ,
675
+ req : & csi.NodeGetInfoRequest {},
676
+ driverStatsUtils : utils .NewFakeStatsUtilsImpl (utils.FakeStatsUtilsFuncStruct {
677
+ GetRegionAndZoneFn : func (nodeName string ) (string , string , error ) {
678
+ return "test-region" , "test-zone" , nil
679
+ },
680
+ }),
681
+ envVars : map [string ]string {
682
+ "KUBE_NODE_NAME" : "testNode" ,
683
+ "MAX_VOLUMES_PER_NODE" : "foobar" ,
684
+ },
685
+ expectedResp : nil ,
686
+ expectedErr : fmt .Errorf ("MAX_VOLUMES_PER_NODE does not contain valid number" ),
687
+ },
645
688
}
646
689
647
690
for _ , tc := range testCases {
648
691
t .Log ("Testcase being executed" , zap .String ("testcase" , tc .testCaseName ))
649
692
650
- _ = os .Setenv ("KUBE_NODE_NAME" , "testNode" )
693
+ for k , v := range tc .envVars {
694
+ t .Setenv (k , v )
695
+ }
651
696
652
697
nodeServer := nodeServer {
653
698
NodeID : testNodeID ,
0 commit comments