@@ -159,12 +159,11 @@ func TestOCITracing(t *testing.T) {
159159 t .Cleanup (trace .Stop )
160160
161161 log .Level = logrus .TraceLevel
162- initialize = _initialize // we want it to re-execute for the test
163162 t .Cleanup (func () {
164163 log .Level = logrus .InfoLevel
165164 initialize = sync .OnceFunc (_initialize )
166- goci . Transport = http . DefaultTransport
167- ghttp . Transport = http . DefaultTransport
165+ ociGatherer = nil
166+ httpGatherer = nil
168167 })
169168 registry := httptest .NewServer (registry .New ())
170169 t .Cleanup (registry .Close )
@@ -179,7 +178,12 @@ func TestOCITracing(t *testing.T) {
179178 require .NoError (t , err )
180179 require .NoError (t , remote .Push (ref , img ))
181180
182- _ , err = gatherFunc (context .Background (), ref .String (), t .TempDir ())
181+ // Initialize directly then call ociGatherer.Gather to test the OCI
182+ // tracing path. Bare localhost refs fall through to the registry's
183+ // default gatherer (no tracing), so we invoke the gatherer directly.
184+ _initialize ()
185+
186+ _ , err = ociGatherer .Gather (context .Background (), ref .String (), t .TempDir ())
183187 require .NoError (t , err )
184188
185189 trace .Stop ()
@@ -215,12 +219,12 @@ func TestHTTPTracing(t *testing.T) {
215219 t .Cleanup (trace .Stop )
216220
217221 log .Level = logrus .TraceLevel
218- initialize = _initialize // we want it to re-execute for the test
222+ initialize = _initialize
219223 t .Cleanup (func () {
220224 log .Level = logrus .InfoLevel
221225 initialize = sync .OnceFunc (_initialize )
222- goci . Transport = http . DefaultTransport
223- ghttp . Transport = http . DefaultTransport
226+ ociGatherer = nil
227+ httpGatherer = nil
224228 })
225229 var requests []string
226230 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -261,32 +265,35 @@ func TestHTTPTracing(t *testing.T) {
261265 assert .Equal (t , 3 , found )
262266}
263267
268+ // TestOCIClientConfiguration verifies _initialize constructs an OCI gatherer.
269+ // OCIGatherer.transport is unexported, so we cannot verify the retry transport
270+ // directly (unlike TestHTTPClientConfiguration). TestOCITracing provides
271+ // integration-level verification that the transport stack is wired correctly.
264272func TestOCIClientConfiguration (t * testing.T ) {
265- defaultMaxRetry := echttp .DefaultRetry .MaxRetry
266273 t .Cleanup (func () {
267- echttp .DefaultRetry .MaxRetry = defaultMaxRetry
274+ ociGatherer = nil
275+ httpGatherer = nil
268276 })
269- echttp .DefaultRetry .MaxRetry = rand .Int () //nolint:gosec // G404 - no need for a secure random here
270277
271278 _initialize ()
272279
273- assert .IsType (t , & retry.Transport {}, goci .Transport )
274-
275- transport := goci .Transport .(* retry.Transport )
276- assert .Equal (t , echttp .DefaultRetry .MaxRetry , transport .Policy ().(* retry.GenericPolicy ).MaxRetry )
280+ assert .IsType (t , & goci.OCIGatherer {}, ociGatherer )
277281}
278282
279283func TestHTTPClientConfiguration (t * testing.T ) {
280284 defaultMaxRetry := echttp .DefaultRetry .MaxRetry
281285 t .Cleanup (func () {
282286 echttp .DefaultRetry .MaxRetry = defaultMaxRetry
287+ ociGatherer = nil
288+ httpGatherer = nil
283289 })
284290 echttp .DefaultRetry .MaxRetry = rand .Int () //nolint:gosec // G404 - no need for a secure random here
285291
286292 _initialize ()
287293
288- assert .IsType (t , & retry.Transport {}, ghttp .Transport )
294+ require .IsType (t , & ghttp.HTTPGatherer {}, httpGatherer )
295+ assert .IsType (t , & retry.Transport {}, httpGatherer .Client .Transport )
289296
290- transport := ghttp .Transport .(* retry.Transport )
297+ transport := httpGatherer . Client .Transport .(* retry.Transport )
291298 assert .Equal (t , echttp .DefaultRetry .MaxRetry , transport .Policy ().(* retry.GenericPolicy ).MaxRetry )
292299}
0 commit comments