Skip to content

Commit

Permalink
daemon: Ensure we call NegotiateAPIVersion first (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr committed Jul 7, 2020
1 parent 92c877e commit 72edbad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit 72edbad

Please sign in to comment.