use a mock
This commit is contained in:
parent
6978fab45c
commit
da5c420ee9
|
|
@ -48,6 +48,11 @@ import (
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// for testing
|
||||||
|
var (
|
||||||
|
newRetry = transport.NewRetry
|
||||||
|
)
|
||||||
|
|
||||||
type withUserAgent struct {
|
type withUserAgent struct {
|
||||||
t http.RoundTripper
|
t http.RoundTripper
|
||||||
}
|
}
|
||||||
|
|
@ -312,7 +317,7 @@ func makeTransport(opts *config.KanikoOptions, registryName string, loader syste
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return transport.NewRetry(tr)
|
return newRetry(tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushLayerToCache pushes layer (tagged with cacheKey) to opts.Cache
|
// pushLayerToCache pushes layer (tagged with cacheKey) to opts.Cache
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ import (
|
||||||
"github.com/google/go-containerregistry/pkg/name"
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/layout"
|
"github.com/google/go-containerregistry/pkg/v1/layout"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/random"
|
"github.com/google/go-containerregistry/pkg/v1/random"
|
||||||
|
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/validate"
|
"github.com/google/go-containerregistry/pkg/v1/validate"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -347,6 +349,13 @@ func Test_makeTransport(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
originalRetry := newRetry
|
||||||
|
newRetry = func(inner http.RoundTripper, _ ...transport.Option) http.RoundTripper {
|
||||||
|
return &retryTransport{
|
||||||
|
inner: inner,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer func() { newRetry = originalRetry }()
|
||||||
var certificatesPath []string
|
var certificatesPath []string
|
||||||
certPool := mockedCertPool{
|
certPool := mockedCertPool{
|
||||||
certificatesPath: certificatesPath,
|
certificatesPath: certificatesPath,
|
||||||
|
|
@ -354,8 +363,8 @@ func Test_makeTransport(t *testing.T) {
|
||||||
var mockedSystemCertLoader systemCertLoader = func() CertPool {
|
var mockedSystemCertLoader systemCertLoader = func() CertPool {
|
||||||
return &certPool
|
return &certPool
|
||||||
}
|
}
|
||||||
transport := makeTransport(tt.opts, registryName, mockedSystemCertLoader)
|
actual := makeTransport(tt.opts, registryName, mockedSystemCertLoader)
|
||||||
tt.check(transport.(*retryTransport).inner.(*http.Transport).TLSClientConfig, &certPool)
|
tt.check(actual.(*retryTransport).inner.(*http.Transport).TLSClientConfig, &certPool)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue