@@ -797,6 +797,114 @@ func TestSetAzureCredentials(t *testing.T) {
797
797
}
798
798
}
799
799
800
+ func TestGetSubnetResourceID (t * testing.T ) {
801
+ testCases := []struct {
802
+ name string
803
+ testFunc func (t * testing.T )
804
+ }{
805
+ {
806
+ name : "NetworkResourceSubscriptionID is Empty" ,
807
+ testFunc : func (t * testing.T ) {
808
+ d := NewFakeDriver ()
809
+ d .cloud .SubscriptionID = "fakeSubID"
810
+ d .cloud .NetworkResourceSubscriptionID = ""
811
+ d .cloud .ResourceGroup = "foo"
812
+ d .cloud .VnetResourceGroup = "foo"
813
+ actualOutput := d .getSubnetResourceID ()
814
+ expectedOutput := fmt .Sprintf (subnetTemplate , d .cloud .SubscriptionID , "foo" , d .cloud .VnetName , d .cloud .SubnetName )
815
+ assert .Equal (t , actualOutput , expectedOutput , "cloud.SubscriptionID should be used as the SubID" )
816
+ },
817
+ },
818
+ {
819
+ name : "NetworkResourceSubscriptionID is not Empty" ,
820
+ testFunc : func (t * testing.T ) {
821
+ d := NewFakeDriver ()
822
+ d .cloud .SubscriptionID = "fakeSubID"
823
+ d .cloud .NetworkResourceSubscriptionID = "fakeNetSubID"
824
+ d .cloud .ResourceGroup = "foo"
825
+ d .cloud .VnetResourceGroup = "foo"
826
+ actualOutput := d .getSubnetResourceID ()
827
+ expectedOutput := fmt .Sprintf (subnetTemplate , d .cloud .NetworkResourceSubscriptionID , "foo" , d .cloud .VnetName , d .cloud .SubnetName )
828
+ assert .Equal (t , actualOutput , expectedOutput , "cloud.NetworkResourceSubscriptionID should be used as the SubID" )
829
+ },
830
+ },
831
+ {
832
+ name : "VnetResourceGroup is Empty" ,
833
+ testFunc : func (t * testing.T ) {
834
+ d := NewFakeDriver ()
835
+ d .cloud .SubscriptionID = "bar"
836
+ d .cloud .NetworkResourceSubscriptionID = "bar"
837
+ d .cloud .ResourceGroup = "fakeResourceGroup"
838
+ d .cloud .VnetResourceGroup = ""
839
+ actualOutput := d .getSubnetResourceID ()
840
+ expectedOutput := fmt .Sprintf (subnetTemplate , "bar" , d .cloud .ResourceGroup , d .cloud .VnetName , d .cloud .SubnetName )
841
+ assert .Equal (t , actualOutput , expectedOutput , "cloud.Resourcegroup should be used as the rg" )
842
+ },
843
+ },
844
+ {
845
+ name : "VnetResourceGroup is not Empty" ,
846
+ testFunc : func (t * testing.T ) {
847
+ d := NewFakeDriver ()
848
+ d .cloud .SubscriptionID = "bar"
849
+ d .cloud .NetworkResourceSubscriptionID = "bar"
850
+ d .cloud .ResourceGroup = "fakeResourceGroup"
851
+ d .cloud .VnetResourceGroup = "fakeVnetResourceGroup"
852
+ actualOutput := d .getSubnetResourceID ()
853
+ expectedOutput := fmt .Sprintf (subnetTemplate , "bar" , d .cloud .VnetResourceGroup , d .cloud .VnetName , d .cloud .SubnetName )
854
+ assert .Equal (t , actualOutput , expectedOutput , "cloud.VnetResourceGroup should be used as the rg" )
855
+ },
856
+ },
857
+ }
858
+ for _ , tc := range testCases {
859
+ t .Run (tc .name , tc .testFunc )
860
+ }
861
+ }
862
+
863
+ func TestUseDataPlaneAPI (t * testing.T ) {
864
+ fakeVolumeID := "unit-test-id"
865
+ fakeAccountName := "unit-test-account"
866
+ testCases := []struct {
867
+ name string
868
+ testFunc func (t * testing.T )
869
+ }{
870
+ {
871
+ name : "volumeID loads correctly" ,
872
+ testFunc : func (t * testing.T ) {
873
+ d := NewFakeDriver ()
874
+ d .dataPlaneAPIVolMap .LoadOrStore (fakeVolumeID , "foo" )
875
+ output := d .useDataPlaneAPI (fakeVolumeID , "" )
876
+ if ! output {
877
+ t .Errorf ("Actual Output: %t, Expected Output: %t" , output , true )
878
+ }
879
+ },
880
+ },
881
+ {
882
+ name : "account loads correctly" ,
883
+ testFunc : func (t * testing.T ) {
884
+ d := NewFakeDriver ()
885
+ d .dataPlaneAPIVolMap .LoadOrStore (fakeAccountName , "foo" )
886
+ output := d .useDataPlaneAPI (fakeAccountName , "" )
887
+ if ! output {
888
+ t .Errorf ("Actual Output: %t, Expected Output: %t" , output , true )
889
+ }
890
+ },
891
+ },
892
+ {
893
+ name : "invalid volumeID and account" ,
894
+ testFunc : func (t * testing.T ) {
895
+ d := NewFakeDriver ()
896
+ output := d .useDataPlaneAPI ("" , "" )
897
+ if output {
898
+ t .Errorf ("Actual Output: %t, Expected Output: %t" , output , false )
899
+ }
900
+ },
901
+ },
902
+ }
903
+ for _ , tc := range testCases {
904
+ t .Run (tc .name , tc .testFunc )
905
+ }
906
+ }
907
+
800
908
func TestAppendDefaultMountOptions (t * testing.T ) {
801
909
tests := []struct {
802
910
options []string
0 commit comments