Skip to content

Commit d391e7f

Browse files
authored
Merge pull request #727 from git-pkgs/stub-gem-specs-test
Stub the gem upstream in the server tests
2 parents 4b86c94 + 1830e33 commit d391e7f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎internal/server/server_test.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ func newTestServer(t *testing.T) *testServer {
8585
cfg.Upstream.Cargo,
8686
cfg.Upstream.CargoDownload,
8787
)
88-
gemHandler := handler.NewGemHandler(proxy, cfg.BaseURL)
88+
gemUpstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
89+
_, _ = io.WriteString(w, "specs")
90+
}))
91+
t.Cleanup(gemUpstream.Close)
92+
gemHandler := handler.NewGemHandlerWithUpstream(proxy, cfg.BaseURL, gemUpstream.URL)
8993
goHandler := handler.NewGoHandler(proxy, cfg.BaseURL)
9094
pypiHandler := handler.NewPyPIHandlerWithUpstreams(proxy, cfg.BaseURL, "", "")
9195
gradleHandler := handler.NewGradleBuildCacheHandler(proxy)
@@ -825,8 +829,8 @@ func TestGemSpecs(t *testing.T) {
825829
w := httptest.NewRecorder()
826830
ts.handler.ServeHTTP(w, req)
827831

828-
if w.Code == http.StatusNotFound {
829-
t.Error("gem handler should be mounted")
832+
if w.Code != http.StatusOK || w.Body.String() != "specs" {
833+
t.Errorf("GET /gem/specs.4.8.gz = %d %q, want 200 with the upstream's body", w.Code, w.Body.String())
830834
}
831835
}
832836

0 commit comments

Comments
 (0)