@@ -53,3 +53,86 @@ func TestValidationPreset_WhenOKDProvidedOnArmArchitecture_thenValidationFailure
53
53
assert .Equal (t , false , validationPass )
54
54
assert .Equal (t , fmt .Sprintf ("preset 'okd' is not supported on %s architecture, please use different preset value" , runtime .GOARCH ), validationMessage )
55
55
}
56
+
57
+ func TestValidateHTTPProxy (t * testing.T ) {
58
+ tests := []struct {
59
+ name string
60
+ noProxyValue string
61
+ expectedValidationResult bool
62
+ expectedValidationStr string
63
+ }{
64
+ {"empty value" , "" , true , "" },
65
+ {"valid http url" , "http://proxy.example.com" , true , "" },
66
+ {"valid https url" , "https://proxy.example.com" , false , "HTTP proxy URL 'https://proxy.example.com' is not valid: url should start with http://" },
67
+ {"valid socks5 url" , "socks5://proxy.example.com" , false , "HTTP proxy URL 'socks5://proxy.example.com' is not valid: url should start with http://" },
68
+ {"type in http scheme" , "htp://proxy.example.com" , false , "HTTP proxy URL 'htp://proxy.example.com' is not valid: url should start with http://" },
69
+ {"no scheme" , "proxy.example.com" , false , "HTTP proxy URL 'proxy.example.com' is not valid: url should start with http://" },
70
+ }
71
+
72
+ for _ , tt := range tests {
73
+ t .Run (tt .name , func (t * testing.T ) {
74
+ actualValidationResult , actualValidationStr := validateHTTPProxy (tt .noProxyValue )
75
+ if actualValidationStr != tt .expectedValidationStr {
76
+ t .Errorf ("validateHTTPProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationStr , tt .expectedValidationStr )
77
+ }
78
+ if actualValidationResult != tt .expectedValidationResult {
79
+ t .Errorf ("validateHTTPProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationResult , tt .expectedValidationResult )
80
+ }
81
+ })
82
+ }
83
+ }
84
+
85
+ func TestValidateHTTPSProxy (t * testing.T ) {
86
+ tests := []struct {
87
+ name string
88
+ noProxyValue string
89
+ expectedValidationResult bool
90
+ expectedValidationStr string
91
+ }{
92
+ {"empty value" , "" , true , "" },
93
+ {"valid https url" , "https://proxy.example.com" , true , "" },
94
+ {"valid http url" , "http://proxy.example.com" , true , "" },
95
+ {"valid socks5 url" , "socks5://proxy.example.com" , false , "HTTPS proxy URL 'socks5://proxy.example.com' is not valid: url should start with http:// or https://" },
96
+ {"type in https scheme" , "htps://proxy.example.com" , false , "HTTPS proxy URL 'htps://proxy.example.com' is not valid: url should start with http:// or https://" },
97
+ {"no scheme" , "proxy.example.com" , false , "HTTPS proxy URL 'proxy.example.com' is not valid: url should start with http:// or https://" },
98
+ }
99
+
100
+ for _ , tt := range tests {
101
+ t .Run (tt .name , func (t * testing.T ) {
102
+ actualValidationResult , actualValidationStr := validateHTTPSProxy (tt .noProxyValue )
103
+ if actualValidationStr != tt .expectedValidationStr {
104
+ t .Errorf ("validateHTTPSProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationStr , tt .expectedValidationStr )
105
+ }
106
+ if actualValidationResult != tt .expectedValidationResult {
107
+ t .Errorf ("validateHTTPSProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationResult , tt .expectedValidationResult )
108
+ }
109
+ })
110
+ }
111
+ }
112
+
113
+ func TestValidateNoProxy (t * testing.T ) {
114
+ tests := []struct {
115
+ name string
116
+ noProxyValue string
117
+ expectedValidationResult bool
118
+ expectedValidationStr string
119
+ }{
120
+ {"empty value" , "" , true , "" },
121
+ {"valid single" , "example.com" , true , "" },
122
+ {"valid multiple" , "localhost,127.0.0.1,example.com" , true , "" },
123
+ {"space in single entry" , "example .com" , false , "NoProxy string can't contain spaces" },
124
+ {"space in between multiple entries" , "localhost, , example.com" , false , "NoProxy string can't contain spaces" },
125
+ }
126
+
127
+ for _ , tt := range tests {
128
+ t .Run (tt .name , func (t * testing.T ) {
129
+ actualValidationResult , actualValidationStr := validateNoProxy (tt .noProxyValue )
130
+ if actualValidationStr != tt .expectedValidationStr {
131
+ t .Errorf ("validateNoProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationStr , tt .expectedValidationStr )
132
+ }
133
+ if actualValidationResult != tt .expectedValidationResult {
134
+ t .Errorf ("validateNoProxy(%s) : got %v, want %v" , tt .noProxyValue , actualValidationResult , tt .expectedValidationResult )
135
+ }
136
+ })
137
+ }
138
+ }
0 commit comments