Skip to content

Commit

Permalink
Merge pull request #1110 from yyb196/two_tag
Browse files Browse the repository at this point in the history
bugfix: do not append latest to image name having a tag already
  • Loading branch information
allencloud authored Apr 12, 2018
2 parents e143482 + 29a26f6 commit 6a70012
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apis/server/image_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (s *Server) pullImage(ctx context.Context, rw http.ResponseWriter, req *htt

if tag == "" {
tag = "latest"
if index := strings.LastIndex(image, ":"); index > 0 {
tag = image[index+1:]
image = image[:index]
}
}
// record the time spent during image pull procedure.
defer func(start time.Time) {
Expand Down
38 changes: 38 additions & 0 deletions apis/server/image_bridge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package server

import (
"context"
"io"
"net/http"
"testing"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/stretchr/testify/assert"
)

type mockImgePull struct {
mgr.ImageMgr
handler func(ctx context.Context, imageRef string, authConfig *types.AuthConfig, out io.Writer) error
}

func (m *mockImgePull) PullImage(ctx context.Context, imageRef string, authConfig *types.AuthConfig, out io.Writer) error {
return m.handler(ctx, imageRef, authConfig, out)
}

func Test_pullImage_without_tag(t *testing.T) {
var s Server

s.ImageMgr = &mockImgePull{
ImageMgr: &mgr.ImageManager{},
handler: func(ctx context.Context, imageRef string, authConfig *types.AuthConfig, out io.Writer) error {
assert.Equal(t, "reg.abc.com/base/os:7.2", imageRef)
return nil
},
}
req := &http.Request{
Form: map[string][]string{"fromImage": {"reg.abc.com/base/os:7.2"}},
Header: map[string][]string{},
}
s.pullImage(context.Background(), nil, req)
}

0 comments on commit 6a70012

Please sign in to comment.