Skip to content

Commit 9df0074

Browse files
committed
test
Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent b5584fe commit 9df0074

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

cmd/nerdctl/container/container_run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ func TestRunFromOCIArchive(t *testing.T) {
786786
tarPath := fmt.Sprintf("%s/%s.tar", buildCtx, imageName)
787787

788788
base.Cmd("build", "--tag", tag, fmt.Sprintf("--output=type=oci,dest=%s", tarPath), buildCtx).AssertOK()
789-
base.Cmd("run", "--rm", fmt.Sprintf("oci-archive://%s", tarPath)).AssertOutContainsAll(fmt.Sprintf("Loaded image: %s", tag), sentinel)
789+
base.Cmd("run", "--rm", fmt.Sprintf("oci-archive://%s", tarPath)).AssertOutContainsAll(tag, sentinel)
790790
}
791791

792792
func TestRunDomainname(t *testing.T) {

pkg/errutil/errors_check.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ func IsErrConnectionRefused(err error) bool {
2424
const errMessage = "connect: connection refused"
2525
return strings.Contains(err.Error(), errMessage)
2626
}
27+
28+
// IsErrHTTPResponseToHTTPSClient returns whether err is
29+
// "http: server gave HTTP response to HTTPS client"
30+
func IsErrHTTPResponseToHTTPSClient(err error) bool {
31+
const errMessage = "server gave HTTP response to HTTPS client"
32+
return strings.Contains(err.Error(), errMessage)
33+
}

pkg/imgutil/transfer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func PullImageWithTransfer(ctx context.Context, client *containerd.Client, parse
8686

8787
transferErr := doTransfer(ctx, client, fetcher, store, options.Quiet, progressWriter)
8888

89-
if transferErr != nil && (errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr)) {
89+
if transferErr != nil && (errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr) || errutil.IsErrHTTPResponseToHTTPSClient(transferErr)) {
9090
if options.GOptions.InsecureRegistry {
91-
log.G(ctx).WithError(err).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain)
91+
log.G(ctx).WithError(transferErr).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain)
9292
fetcher, err = createOCIRegistry(ctx, parsedReference, options.GOptions, true)
9393
if err != nil {
9494
return nil, err
@@ -158,9 +158,9 @@ func PushImageWithTransfer(ctx context.Context, client *containerd.Client, parse
158158

159159
transferErr := doTransfer(ctx, client, source, pusher, options.Quiet, progressWriter)
160160

161-
if transferErr != nil && (errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr)) {
161+
if transferErr != nil && (errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr) || errutil.IsErrHTTPResponseToHTTPSClient(transferErr)) {
162162
if options.GOptions.InsecureRegistry {
163-
log.G(ctx).WithError(err).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain)
163+
log.G(ctx).WithError(transferErr).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain)
164164
pusher, err = createOCIRegistry(ctx, parsedReference, options.GOptions, true)
165165
if err != nil {
166166
return err

0 commit comments

Comments
 (0)