| 3 | import "testing" |
| 4 | |
| 5 | func TestParseURL(t *testing.T) { |
| 6 | tests := []struct { |
| 7 | in string |
| 8 | want string |
| 9 | }{ |
| 10 | {"https://golang.org", "https://golang.org"}, |
| 11 | {"https://golang.org:443/test", "https://golang.org:443/test"}, |
| 12 | {"localhost:8080/test", "https://localhost:8080/test"}, |
| 13 | {"localhost:80/test", "http://localhost:80/test"}, |
| 14 | {"//localhost:8080/test", "https://localhost:8080/test"}, |
| 15 | {"//localhost:80/test", "http://localhost:80/test"}, |
| 16 | } |
| 17 | |
| 18 | for _, test := range tests { |
| 19 | u := parseURL(test.in) |
| 20 | if u.String() != test.want { |
| 21 | t.Errorf("Given: %s\nwant: %s\ngot: %s", test.in, test.want, u.String()) |
| 22 | } |
| 23 | } |
| 24 | } |