From d90994408fed47a8fb7a2d82e2f751d8da7067e4 Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Sat, 4 Jun 2022 16:20:04 +0100 Subject: Generate destinations with a regular expression --- resp_test.go | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'resp_test.go') 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) - } - } -} -- cgit v1.2.3-70-g09d2