Allow conditional fetching of manifests with the registry client.
Add a functional argument to pass a digest to (ManifestService).GetByTag().
If the digest matches an empty manifest and nil error are returned.
See 6bedf7d1cd
for server implementation.
Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
This commit is contained in:
parent
af3f674323
commit
caf989a572
3 changed files with 83 additions and 18 deletions
|
@ -46,6 +46,7 @@ func newRandomBlob(size int) (digest.Digest, []byte) {
|
|||
}
|
||||
|
||||
func addTestFetch(repo string, dgst digest.Digest, content []byte, m *testutil.RequestResponseMap) {
|
||||
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
|
@ -60,6 +61,7 @@ func addTestFetch(repo string, dgst digest.Digest, content []byte, m *testutil.R
|
|||
}),
|
||||
},
|
||||
})
|
||||
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
|
@ -398,6 +400,40 @@ func newRandomSchemaV1Manifest(name, tag string, blobCount int) (*manifest.Signe
|
|||
return m, dgst
|
||||
}
|
||||
|
||||
func addTestManifestWithEtag(repo, reference string, content []byte, m *testutil.RequestResponseMap, dgst string) {
|
||||
actualDigest, _ := digest.FromBytes(content)
|
||||
getReqWithEtag := testutil.Request{
|
||||
Method: "GET",
|
||||
Route: "/v2/" + repo + "/manifests/" + reference,
|
||||
Headers: http.Header(map[string][]string{
|
||||
"Etag": {dgst},
|
||||
}),
|
||||
}
|
||||
|
||||
var getRespWithEtag testutil.Response
|
||||
if actualDigest.String() == dgst {
|
||||
getRespWithEtag = testutil.Response{
|
||||
StatusCode: http.StatusNotModified,
|
||||
Body: []byte{},
|
||||
Headers: http.Header(map[string][]string{
|
||||
"Content-Length": {"0"},
|
||||
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
||||
}),
|
||||
}
|
||||
} else {
|
||||
getRespWithEtag = testutil.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: content,
|
||||
Headers: http.Header(map[string][]string{
|
||||
"Content-Length": {fmt.Sprint(len(content))},
|
||||
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
||||
}),
|
||||
}
|
||||
|
||||
}
|
||||
*m = append(*m, testutil.RequestResponseMapping{Request: getReqWithEtag, Response: getRespWithEtag})
|
||||
}
|
||||
|
||||
func addTestManifest(repo, reference string, content []byte, m *testutil.RequestResponseMap) {
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
|
@ -487,11 +523,11 @@ func TestManifestFetch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestManifestFetchByTag(t *testing.T) {
|
||||
func TestManifestFetchWithEtag(t *testing.T) {
|
||||
repo := "test.example.com/repo/by/tag"
|
||||
m1, _ := newRandomSchemaV1Manifest(repo, "latest", 6)
|
||||
m1, d1 := newRandomSchemaV1Manifest(repo, "latest", 6)
|
||||
var m testutil.RequestResponseMap
|
||||
addTestManifest(repo, "latest", m1.Raw, &m)
|
||||
addTestManifestWithEtag(repo, "latest", m1.Raw, &m, d1.String())
|
||||
|
||||
e, c := testServer(m)
|
||||
defer c()
|
||||
|
@ -502,20 +538,12 @@ func TestManifestFetchByTag(t *testing.T) {
|
|||
}
|
||||
|
||||
ms := r.Manifests()
|
||||
ok, err := ms.ExistsByTag("latest")
|
||||
m2, err := ms.GetByTag("latest", AddEtagToTag("latest", d1.String()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("Manifest does not exist")
|
||||
}
|
||||
|
||||
manifest, err := ms.GetByTag("latest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := checkEqualManifest(manifest, m1); err != nil {
|
||||
t.Fatal(err)
|
||||
if m2 != nil {
|
||||
t.Fatal("Expected empty manifest for matching etag")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue