File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
cmd/kubeadm/app/apis/kubeadm/validation Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -914,3 +914,50 @@ func TestValidateSocketPath(t *testing.T) {
914
914
}
915
915
}
916
916
}
917
+
918
+ func TestValidateURLs (t * testing.T ) {
919
+ var tests = []struct {
920
+ name string
921
+ urls []string
922
+ requireHTTPS bool
923
+ expectedErrors bool
924
+ }{
925
+ {
926
+ name : "valid urls (https not required)" ,
927
+ urls : []string {"http://example.com" , "https://example.org" },
928
+ requireHTTPS : false ,
929
+ expectedErrors : false ,
930
+ },
931
+ {
932
+ name : "valid urls (https required)" ,
933
+ urls : []string {"https://example.com" , "https://example.org" },
934
+ requireHTTPS : true ,
935
+ expectedErrors : false ,
936
+ },
937
+ {
938
+ name : "invalid url (https required)" ,
939
+ urls : []string {"http://example.com" , "https://example.org" },
940
+ requireHTTPS : true ,
941
+ expectedErrors : true ,
942
+ },
943
+ {
944
+ name : "URL parse error" ,
945
+ urls : []string {"::://example.com" },
946
+ requireHTTPS : false ,
947
+ expectedErrors : true ,
948
+ },
949
+ {
950
+ name : "URL without scheme" ,
951
+ urls : []string {"example.com" },
952
+ requireHTTPS : false ,
953
+ expectedErrors : true ,
954
+ },
955
+ }
956
+ for _ , tc := range tests {
957
+ actual := ValidateURLs (tc .urls , tc .requireHTTPS , nil )
958
+ actualErrors := len (actual ) > 0
959
+ if actualErrors != tc .expectedErrors {
960
+ t .Errorf ("error:\n \t expected: %t\n \t actual: %t" , tc .expectedErrors , actualErrors )
961
+ }
962
+ }
963
+ }
You can’t perform that action at this time.
0 commit comments