Skip to content

Commit

Permalink
Merge pull request kubernetes#91431 from prasadkatti/add_validate_url…
Browse files Browse the repository at this point in the history
…s_tests

Add tests for ValidateURLs (kubeadm validation)
  • Loading branch information
k8s-ci-robot committed May 27, 2020
2 parents 87473a5 + a85fc10 commit 356c121
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/validation/validation_test.go
Expand Up @@ -914,3 +914,50 @@ func TestValidateSocketPath(t *testing.T) {
}
}
}

func TestValidateURLs(t *testing.T) {
var tests = []struct {
name string
urls []string
requireHTTPS bool
expectedErrors bool
}{
{
name: "valid urls (https not required)",
urls: []string{"http://example.com", "https://example.org"},
requireHTTPS: false,
expectedErrors: false,
},
{
name: "valid urls (https required)",
urls: []string{"https://example.com", "https://example.org"},
requireHTTPS: true,
expectedErrors: false,
},
{
name: "invalid url (https required)",
urls: []string{"http://example.com", "https://example.org"},
requireHTTPS: true,
expectedErrors: true,
},
{
name: "URL parse error",
urls: []string{"::://example.com"},
requireHTTPS: false,
expectedErrors: true,
},
{
name: "URL without scheme",
urls: []string{"example.com"},
requireHTTPS: false,
expectedErrors: true,
},
}
for _, tc := range tests {
actual := ValidateURLs(tc.urls, tc.requireHTTPS, nil)
actualErrors := len(actual) > 0
if actualErrors != tc.expectedErrors {
t.Errorf("error:\n\texpected: %t\n\t actual: %t", tc.expectedErrors, actualErrors)
}
}
}

0 comments on commit 356c121

Please sign in to comment.