Skip to content

daemon: Ensure we call NegotiateAPIVersion first #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/v1/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func (i *imageOpener) Open() (v1.Image, error) {
return nil, err
}

i.client.NegotiateAPIVersion(context.Background())

tb, err := tarball.Image(opener, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -117,6 +115,7 @@ func Image(ref name.Reference, options ...ImageOption) (v1.Image, error) {
return nil, err
}
}
i.client.NegotiateAPIVersion(context.Background())

return i.Open()
}
14 changes: 11 additions & 3 deletions pkg/v1/daemon/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package daemon

import (
"context"
"errors"
"io"
"os"
"testing"
Expand All @@ -30,12 +31,19 @@ var imagePath = "../tarball/testdata/test_image_1.tar"

type MockImageSaver struct {
Client
path string
path string
negotiated bool
}

func (m *MockImageSaver) NegotiateAPIVersion(ctx context.Context) {}
func (m *MockImageSaver) NegotiateAPIVersion(ctx context.Context) {
m.negotiated = true
}

func (m *MockImageSaver) ImageSave(_ context.Context, _ []string) (io.ReadCloser, error) {
if !m.negotiated {
return nil, errors.New("you forgot to call NegotiateAPIVersion before calling ImageSave")

}
return os.Open(m.path)
}

Expand All @@ -59,7 +67,7 @@ func TestImage(t *testing.T) {

dmn, err := Image(tag, opts...)
if err != nil {
t.Errorf("Error loading daemon image: %s", err)
t.Fatalf("Error loading daemon image: %s", err)
}
if err := compare.Images(img, dmn); err != nil {
t.Errorf("compare.Images: %v", err)
Expand Down