diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-06-04 16:20:04 +0100 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-06-04 16:20:04 +0100 |
| commit | d90994408fed47a8fb7a2d82e2f751d8da7067e4 (patch) | |
| tree | 5ad0d4570f81877873f5b7dc98a3f2791130b1ed /resp_test.go | |
| parent | de889e3a7e198c6a47fa6c47a4e2526259f0ee98 (diff) | |
Generate destinations with a regular expression
Diffstat (limited to 'resp_test.go')
| -rw-r--r-- | resp_test.go | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/resp_test.go b/resp_test.go index 2185403..1f8c458 100644 --- a/resp_test.go +++ b/resp_test.go @@ -7,11 +7,12 @@ import ( "io" "net/http" "net/http/httptest" + "regexp" "testing" ) func TestRedirector_ServeHTTP(t *testing.T) { - r := &redirector{"src.example.com/x", "https://example.com/git", "git"} + r := &redirector{regexp.MustCompile(`src\.example\.com/x`), "https://example.com/git", "git"} t.Run("GoVisit", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "https://src.example.com/x/foo?go-get=1", nil) @@ -56,25 +57,3 @@ func TestRedirector_ServeHTTP(t *testing.T) { } }) } - -func TestRedirector_getRepo(t *testing.T) { - r := &redirector{"src.example.com/x/", "https://example.com/git/", "git"} - for _, tc := range []struct{ pkg, expected string }{ - {"src.example.com/x/foo", "https://example.com/git/foo"}, - {"src.example.com/x/foo/bar", "https://example.com/git/foo"}, - } { - if actual := r.getRepo(tc.pkg); actual != tc.expected { - t.Errorf("expected %q, got %q", tc.expected, actual) - } - } - - r = &redirector{"src.example.com/x", "https://example.com/git", "git"} - for _, tc := range []struct{ pkg, expected string }{ - {"src.example.com/x/foo", "https://example.com/git/foo"}, - {"src.example.com/x/foo/bar", "https://example.com/git/foo"}, - } { - if actual := r.getRepo(tc.pkg); actual != tc.expected { - t.Errorf("expected %q, got %q", tc.expected, actual) - } - } -} |
