Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
test for checkURL
Browse files Browse the repository at this point in the history
  • Loading branch information
gbmor committed Feb 9, 2020
1 parent 4ef9c82 commit 951fe12
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions methods/validation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package methods

import "testing"

var checkURLCases = []struct {
name string
url string
expectErr bool
}{
{
name: "valid http://",
url: "http://example.com",
expectErr: false,
},
{
name: "valid https://",
url: "https://example.com",
expectErr: false,
},
{
name: "empty url",
url: "",
expectErr: true,
},
{
name: "invalid protocol",
url: "htp://example.com",
expectErr: true,
},
{
name: "disallowed protocol",
url: "irc://example.com",
expectErr: true,
},
}

func Test_checkURL(t *testing.T) {
for _, tt := range checkURLCases {
out, err := checkURL(tt.url)
if err != nil && !tt.expectErr {
t.Errorf("%s :: %s", tt.name, err.Error())
}
if out != tt.url && !tt.expectErr {
t.Errorf("URL mangled. Got %s - expected %s", out, tt.url)
}
if out != "" && err != nil && tt.expectErr {
t.Errorf("Didn't fail when expected")
}
}
}

0 comments on commit 951fe12

Please sign in to comment.