TestNewResolver_UsesProvidedTransport guards that the transport passed to NewResolver actually carries OCI traffic. The httptest server returns 401 so the resolver fails fast without real network access.
(t *testing.T)
| 49 | // NewResolver actually carries OCI traffic. The httptest server returns 401 |
| 50 | // so the resolver fails fast without real network access. |
| 51 | func TestNewResolver_UsesProvidedTransport(t *testing.T) { |
| 52 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 53 | w.WriteHeader(http.StatusUnauthorized) |
| 54 | })) |
| 55 | t.Cleanup(server.Close) |
| 56 | |
| 57 | host := server.Listener.Addr().String() |
| 58 | // Bare *http.Transport (Proxy: nil) keeps the test hermetic — delegating |
| 59 | // to http.DefaultTransport would honor HTTP[S]_PROXY env vars in CI or |
| 60 | // dev shells and route requests away from our local httptest server. |
| 61 | rec := &recordingRoundTripper{delegate: &http.Transport{}} |
| 62 | |
| 63 | // Mark the test host insecure so the resolver uses HTTP scheme; this |
| 64 | // avoids needing a TLS cert chain just to exercise plumbing. |
| 65 | resolver := NewResolver(&configfile.ConfigFile{}, rec, host) |
| 66 | |
| 67 | // We expect 401, but only care that the request reached our transport. |
| 68 | _, _, _ = resolver.Resolve(t.Context(), host+"/test/image:latest") |
| 69 | |
| 70 | assert.Assert(t, rec.calls.Load() > 0, |
| 71 | "resolver did not invoke the supplied transport — wiring is broken") |
| 72 | } |
| 73 | |
| 74 | // TestNewResolver_AuthorizerUsesProvidedTransport guards that the docker |
| 75 | // authorizer's token fetch goes through the supplied transport, not |
nothing calls this directly
no test coverage detected