(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestValidateUrl(t *testing.T) { |
| 55 | type testCase struct { |
| 56 | input string |
| 57 | expectedOutput string |
| 58 | } |
| 59 | testCases := []testCase{ |
| 60 | {"http://localhost", "http://localhost"}, |
| 61 | {"http://localhost/", "http://localhost"}, |
| 62 | {"http://localhost/api", "http://localhost"}, |
| 63 | {"http://localhost/api/", "http://localhost"}, |
| 64 | {"https://localhost", "https://localhost"}, |
| 65 | {"https://localhost/", "https://localhost"}, |
| 66 | {"https://localhost/api", "https://localhost"}, |
| 67 | {"https://localhost/api/", "https://localhost"}, |
| 68 | {"https://localhost:8080", "https://localhost:8080"}, |
| 69 | {"https://localhost:8080/", "https://localhost:8080"}, |
| 70 | {"https://localhost:8080/api", "https://localhost:8080"}, |
| 71 | {"https://localhost:8080/api/", "https://localhost:8080"}, |
| 72 | {"localhost", "http://localhost"}, |
| 73 | {"localhost/", "http://localhost/"}, |
| 74 | {"localhost/api", "http://localhost/api"}, |
| 75 | {"localhost/api/", "http://localhost/api/"}, |
| 76 | {"localhost:8080", "http://localhost:8080"}, |
| 77 | {"localhost:8080/", "http://localhost:8080/"}, |
| 78 | {"localhost:8080/api", "http://localhost:8080/api"}, |
| 79 | {"localhost:8080/api/", "http://localhost:8080/api/"}, |
| 80 | {"localhost:8080/api/?asdf", "http://localhost:8080/api/?asdf"}, |
| 81 | {"http://127.0.0.1:8080", "http://127.0.0.1:8080"}, |
| 82 | {"127.0.0.1:8080", "http://127.0.0.1:8080"}, |
| 83 | {"127.0.0.1", "http://127.0.0.1"}, |
| 84 | {"https://127.0.0.1:8080", "https://127.0.0.1:8080"}, |
| 85 | {"[::1]:8080", "http://[::1]:8080"}, |
| 86 | {"http://[::1]", "http://[::1]"}, |
| 87 | {"http://[::1]:8080", "http://[::1]:8080"}, |
| 88 | {"[::1]", "http://[::1]"}, |
| 89 | {"https://example.com", "https://example.com"}, |
| 90 | {"example.com", "http://example.com"}, |
| 91 | {"http://hello.example.com", "http://hello.example.com"}, |
| 92 | {"hello.example.com", "http://hello.example.com"}, |
| 93 | {"hello.example.com:8080", "http://hello.example.com:8080"}, |
| 94 | {"https://hello.example.com:8080", "https://hello.example.com:8080"}, |
| 95 | {"https://bücher.example.com", "https://xn--bcher-kva.example.com"}, |
| 96 | {"bücher.example.com", "http://xn--bcher-kva.example.com"}, |
| 97 | {"https%3A%2F%2Fhello.example.com", "https://hello.example.com"}, |
| 98 | {"https://alex:12345@hello.example.com:8080", "https://hello.example.com:8080"}, |
| 99 | } |
| 100 | for i, testCase := range testCases { |
| 101 | validUrl, err := ValidateUrl(testCase.input) |
| 102 | assert.NoError(t, err, "test case %v", i) |
| 103 | assert.Equal(t, testCase.expectedOutput, validUrl.String(), "test case %v", i) |
| 104 | } |
| 105 | |
| 106 | validUrl, err := ValidateUrl("") |
| 107 | assert.Equal(t, fmt.Errorf("URL should not be empty"), err) |
| 108 | assert.Empty(t, validUrl) |
| 109 | |
| 110 | validUrl, err = ValidateUrl("ftp://alex:12345@hello.example.com:8080/robot.txt") |
| 111 | assert.Equal(t, "Currently Cloudflare Tunnel does not support ftp protocol.", err.Error()) |
nothing calls this directly
no test coverage detected