@@ -18,7 +18,7 @@ package driver
1818
1919import (
2020 "errors"
21- "os "
21+ "fmt "
2222 "reflect"
2323 "testing"
2424
@@ -618,6 +618,7 @@ func TestNodeGetInfo(t *testing.T) {
618618 testCases := []struct {
619619 testCaseName string
620620 driverStatsUtils utils.StatsUtils
621+ envVars map [string ]string
621622 req * csi.NodeGetInfoRequest
622623 expectedResp * csi.NodeGetInfoResponse
623624 expectedErr error
@@ -630,6 +631,9 @@ func TestNodeGetInfo(t *testing.T) {
630631 return "test-region" , "test-zone" , nil
631632 },
632633 }),
634+ envVars : map [string ]string {
635+ "KUBE_NODE_NAME" : "testNode" ,
636+ },
633637 expectedResp : & csi.NodeGetInfoResponse {
634638 NodeId : testNodeID ,
635639 MaxVolumesPerNode : constants .DefaultVolumesPerNode ,
@@ -642,12 +646,53 @@ func TestNodeGetInfo(t *testing.T) {
642646 },
643647 expectedErr : nil ,
644648 },
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+ },
645688 }
646689
647690 for _ , tc := range testCases {
648691 t .Log ("Testcase being executed" , zap .String ("testcase" , tc .testCaseName ))
649692
650- _ = os .Setenv ("KUBE_NODE_NAME" , "testNode" )
693+ for k , v := range tc .envVars {
694+ t .Setenv (k , v )
695+ }
651696
652697 nodeServer := nodeServer {
653698 NodeID : testNodeID ,
0 commit comments