This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |