Skip to content

Commit

Permalink
Only attempt to mount for MountableLayer (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored Mar 8, 2019
1 parent fcd5acb commit 88208fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ func (w *writer) checkExistingManifest(h v1.Hash, mt types.MediaType) (bool, err
func (w *writer) initiateUpload(from, mount string) (location string, mounted bool, err error) {
u := w.url(fmt.Sprintf("/v2/%s/blobs/uploads/", w.ref.Context().RepositoryStr()))
uv := url.Values{}
if mount != "" {
if mount != "" && from != "" {
// Quay will fail if we specify a "mount" without a "from".
uv["mount"] = []string{mount}
}
if from != "" {
uv["from"] = []string{from}
}
u.RawQuery = uv.Encode()
Expand Down
12 changes: 8 additions & 4 deletions pkg/v1/remote/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestInitiateUploadNoMountsExists(t *testing.T) {
expectedPath := fmt.Sprintf("/v2/%s/blobs/uploads/", expectedRepo)
expectedQuery := url.Values{
"mount": []string{h.String()},
"from": []string{"baz/bar"},
}.Encode()

w, closer, err := setupWriter(expectedRepo, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -248,7 +249,7 @@ func TestInitiateUploadNoMountsExists(t *testing.T) {
}
defer closer.Close()

_, mounted, err := w.initiateUpload("", h.String())
_, mounted, err := w.initiateUpload("baz/bar", h.String())
if err != nil {
t.Errorf("intiateUpload() = %v", err)
}
Expand All @@ -264,6 +265,7 @@ func TestInitiateUploadNoMountsInitiated(t *testing.T) {
expectedPath := fmt.Sprintf("/v2/%s/blobs/uploads/", expectedRepo)
expectedQuery := url.Values{
"mount": []string{h.String()},
"from": []string{"baz/bar"},
}.Encode()
expectedLocation := "https://somewhere.io/upload?foo=bar"

Expand All @@ -285,7 +287,7 @@ func TestInitiateUploadNoMountsInitiated(t *testing.T) {
}
defer closer.Close()

location, mounted, err := w.initiateUpload("", h.String())
location, mounted, err := w.initiateUpload("baz/bar", h.String())
if err != nil {
t.Errorf("intiateUpload() = %v", err)
}
Expand All @@ -304,6 +306,7 @@ func TestInitiateUploadNoMountsBadStatus(t *testing.T) {
expectedPath := fmt.Sprintf("/v2/%s/blobs/uploads/", expectedRepo)
expectedQuery := url.Values{
"mount": []string{h.String()},
"from": []string{"baz/bar"},
}.Encode()

w, closer, err := setupWriter(expectedRepo, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -323,7 +326,7 @@ func TestInitiateUploadNoMountsBadStatus(t *testing.T) {
}
defer closer.Close()

location, mounted, err := w.initiateUpload("", h.String())
location, mounted, err := w.initiateUpload("baz/bar", h.String())
if err == nil {
t.Errorf("intiateUpload() = %v, %v; wanted error", location, mounted)
}
Expand All @@ -337,6 +340,7 @@ func TestInitiateUploadMountsWithMountFromDifferentRegistry(t *testing.T) {
expectedPath := fmt.Sprintf("/v2/%s/blobs/uploads/", expectedRepo)
expectedQuery := url.Values{
"mount": []string{h.String()},
"from": []string{"baz/bar"},
}.Encode()

img = &mountableImage{
Expand All @@ -361,7 +365,7 @@ func TestInitiateUploadMountsWithMountFromDifferentRegistry(t *testing.T) {
}
defer closer.Close()

_, mounted, err := w.initiateUpload("", h.String())
_, mounted, err := w.initiateUpload("baz/bar", h.String())
if err != nil {
t.Errorf("intiateUpload() = %v", err)
}
Expand Down

0 comments on commit 88208fd

Please sign in to comment.