forked from TrueCloudLab/distribution
fit get status issue
1, return the right upload offset for client when asks. 2, do not call ResumeBlobUpload on getting status. 3, return 416 rather than 404 on failed to patch chunk blob. 4, add the missing upload close Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
fb2188868d
commit
bad5dcb602
2 changed files with 55 additions and 16 deletions
|
@ -687,6 +687,17 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|||
layerFile.Seek(0, 0)
|
||||
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
||||
uploadURLBase, dgst := pushChunk(t, env.builder, imageName, uploadURLBase, layerFile, layerLength)
|
||||
|
||||
// -----------------------------------------
|
||||
// Check the chunk upload status
|
||||
_, end, err := getUploadStatus(uploadURLBase)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error doing chunk upload check: %v", err)
|
||||
}
|
||||
if end+1 != layerLength {
|
||||
t.Fatalf("getting wrong chunk upload status: %d", end)
|
||||
}
|
||||
|
||||
finishUpload(t, env.builder, imageName, uploadURLBase, dgst)
|
||||
|
||||
// -----------------------------------------
|
||||
|
@ -2487,6 +2498,27 @@ func pushLayer(t *testing.T, ub *v2.URLBuilder, name reference.Named, dgst diges
|
|||
return resp.Header.Get("Location")
|
||||
}
|
||||
|
||||
func getUploadStatus(location string) (string, int64, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, location, nil)
|
||||
if err != nil {
|
||||
return location, -1, err
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return location, -1, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
_, end, err := parseContentRange(resp.Header.Get("Range"))
|
||||
if err != nil {
|
||||
return location, -1, err
|
||||
}
|
||||
|
||||
return resp.Header.Get("Location"), end, nil
|
||||
}
|
||||
|
||||
func finishUpload(t *testing.T, ub *v2.URLBuilder, name reference.Named, uploadURLBase string, dgst digest.Digest) string {
|
||||
resp, err := doPushLayer(t, ub, name, dgst, uploadURLBase, nil)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue