2018-02-05 16:05:59 -05:00
|
|
|
package reference // import "github.com/docker/docker/reference"
|
2015-11-18 17:16:21 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
2015-11-25 15:42:40 -05:00
|
|
|
"path/filepath"
|
2015-11-18 17:16:21 -05:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2019-08-05 10:37:47 -04:00
|
|
|
digest "github.com/opencontainers/go-digest"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2015-11-18 17:16:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-09-15 19:37:32 -04:00
|
|
|
saveLoadTestCases = map[string]digest.Digest{
|
2020-02-11 08:16:13 -05:00
|
|
|
"registry:5000/foobar:HEAD": "sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6",
|
|
|
|
"registry:5000/foobar:alternate": "sha256:ae300ebc4a4f00693702cfb0a5e0b7bc527b353828dc86ad09fb95c8a681b793",
|
|
|
|
"registry:5000/foobar:latest": "sha256:6153498b9ac00968d71b66cca4eac37e990b5f9eb50c26877eb8799c8847451b",
|
|
|
|
"registry:5000/foobar:master": "sha256:6c9917af4c4e05001b346421959d7ea81b6dc9d25718466a37a6add865dfd7fc",
|
|
|
|
"jess/hollywood:latest": "sha256:ae7a5519a0a55a2d4ef20ddcbd5d0ca0888a1f7ab806acc8e2a27baf46f529fe",
|
2015-11-18 17:16:21 -05:00
|
|
|
"registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6": "sha256:24126a56805beb9711be5f4590cc2eb55ab8d4a85ebd618eed72bb19fc50631c",
|
|
|
|
"busybox:latest": "sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
|
|
|
}
|
|
|
|
|
|
|
|
marshalledSaveLoadTestCases = []byte(`{"Repositories":{"busybox":{"busybox:latest":"sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c"},"jess/hollywood":{"jess/hollywood:latest":"sha256:ae7a5519a0a55a2d4ef20ddcbd5d0ca0888a1f7ab806acc8e2a27baf46f529fe"},"registry":{"registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6":"sha256:24126a56805beb9711be5f4590cc2eb55ab8d4a85ebd618eed72bb19fc50631c"},"registry:5000/foobar":{"registry:5000/foobar:HEAD":"sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6","registry:5000/foobar:alternate":"sha256:ae300ebc4a4f00693702cfb0a5e0b7bc527b353828dc86ad09fb95c8a681b793","registry:5000/foobar:latest":"sha256:6153498b9ac00968d71b66cca4eac37e990b5f9eb50c26877eb8799c8847451b","registry:5000/foobar:master":"sha256:6c9917af4c4e05001b346421959d7ea81b6dc9d25718466a37a6add865dfd7fc"}}}`)
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoad(t *testing.T) {
|
2021-08-24 06:10:50 -04:00
|
|
|
jsonFile, err := os.CreateTemp("", "tag-store-test")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp file: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(jsonFile.Name())
|
|
|
|
|
|
|
|
// Write canned json to the temp file
|
|
|
|
_, err = jsonFile.Write(marshalledSaveLoadTestCases)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error writing to temp file: %v", err)
|
|
|
|
}
|
|
|
|
jsonFile.Close()
|
|
|
|
|
2017-08-17 18:43:36 -04:00
|
|
|
store, err := NewReferenceStore(jsonFile.Name())
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating tag store: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for refStr, expectedID := range saveLoadTestCases {
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed(refStr)
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to parse reference: %v", err)
|
|
|
|
}
|
|
|
|
id, err := store.Get(ref)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not find reference %s: %v", refStr, err)
|
|
|
|
}
|
|
|
|
if id != expectedID {
|
|
|
|
t.Fatalf("expected %s - got %s", expectedID, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSave(t *testing.T) {
|
2021-08-24 06:10:50 -04:00
|
|
|
jsonFile, err := os.CreateTemp("", "tag-store-test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-09-08 18:00:14 -04:00
|
|
|
|
2015-11-18 17:16:21 -05:00
|
|
|
_, err = jsonFile.Write([]byte(`{}`))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-11-18 17:16:21 -05:00
|
|
|
jsonFile.Close()
|
|
|
|
defer os.RemoveAll(jsonFile.Name())
|
|
|
|
|
2017-08-17 18:43:36 -04:00
|
|
|
store, err := NewReferenceStore(jsonFile.Name())
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating tag store: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for refStr, id := range saveLoadTestCases {
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed(refStr)
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to parse reference: %v", err)
|
|
|
|
}
|
2017-01-25 19:54:18 -05:00
|
|
|
if canonical, ok := ref.(reference.Canonical); ok {
|
2015-11-25 15:42:40 -05:00
|
|
|
err = store.AddDigest(canonical, id, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not add digest reference %s: %v", refStr, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = store.AddTag(ref, id, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not add reference %s: %v", refStr, err)
|
|
|
|
}
|
2015-11-18 17:16:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
jsonBytes, err := os.ReadFile(jsonFile.Name())
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read json file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(jsonBytes, marshalledSaveLoadTestCases) {
|
|
|
|
t.Fatalf("save output did not match expectations\nexpected:\n%s\ngot:\n%s", marshalledSaveLoadTestCases, jsonBytes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddDeleteGet(t *testing.T) {
|
2021-08-24 06:10:50 -04:00
|
|
|
jsonFile, err := os.CreateTemp("", "tag-store-test")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp file: %v", err)
|
|
|
|
}
|
|
|
|
_, err = jsonFile.Write([]byte(`{}`))
|
2019-08-05 11:50:51 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
_ = jsonFile.Close()
|
|
|
|
defer func() { _ = os.RemoveAll(jsonFile.Name()) }()
|
2015-11-18 17:16:21 -05:00
|
|
|
|
2017-08-17 18:43:36 -04:00
|
|
|
store, err := NewReferenceStore(jsonFile.Name())
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating tag store: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-09-15 19:37:32 -04:00
|
|
|
testImageID1 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9c")
|
|
|
|
testImageID2 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9d")
|
|
|
|
testImageID3 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9e")
|
2015-11-18 17:16:21 -05:00
|
|
|
|
|
|
|
// Try adding a reference with no tag or digest
|
2017-01-25 19:54:18 -05:00
|
|
|
nameOnly, err := reference.ParseNormalizedNamed("username/repo")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(nameOnly, testImageID1, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a few references
|
2017-01-25 19:54:18 -05:00
|
|
|
ref1, err := reference.ParseNormalizedNamed("username/repo1:latest")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref1, testImageID1, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
ref2, err := reference.ParseNormalizedNamed("username/repo1:old")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref2, testImageID2, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
ref3, err := reference.ParseNormalizedNamed("username/repo1:alias")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref3, testImageID1, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
ref4, err := reference.ParseNormalizedNamed("username/repo2:latest")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref4, testImageID2, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
Don't fail on two concurrent reference.store.AddDigest calls
reference.store.addReference fails when adding a digest reference
that already exists (regardless of the reference target). Both
callers (via reference.store.AddDigest) do check in advance, using
reference.store.Get, whether the digest reference exists before
calling AddDigest, but the reference store lock is released between
the two calls, so if another thread sets the reference in the meantime,
AddDigest may fail with
> Cannot overwrite digest ...
.
Handle this by checking that the pre-existing reference points at the
same image, i.e. that there is nothing to do, and succeeding immediately
in that case. This is even cheaper, avoids a reference.store.save() call.
(In principle, the same failure could have happened via
reference.store.AddTag, as
> Conflict: Tag %s is already set to image %s, if you want to replace it, please use -f option
but almost all callers (except for migrate/v1.Migrate, which is run
single-threaded anyway) set the "force" parameter of AddTag to true,
which makes the race invisible. This commit does not change the behavior
of that case, except for speeding it up by avoiding the
reference.store.save() call.)
The existing reference.store.Get checks are now, in a sense, redundant
as such, but their existence allows the callers to provide nice
context-dependent error messages, so this commit leaves them unchanged.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-09-06 17:24:06 -04:00
|
|
|
// Write the same values again; should silently succeed
|
|
|
|
if err = store.AddTag(ref4, testImageID2, false); err != nil {
|
|
|
|
t.Fatalf("error redundantly adding to store: %v", err)
|
|
|
|
}
|
2015-11-18 17:16:21 -05:00
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
ref5, err := reference.ParseNormalizedNamed("username/repo3@sha256:58153dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
2017-01-25 19:54:18 -05:00
|
|
|
if err = store.AddDigest(ref5.(reference.Canonical), testImageID2, false); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("error adding to store: %v", err)
|
|
|
|
}
|
Don't fail on two concurrent reference.store.AddDigest calls
reference.store.addReference fails when adding a digest reference
that already exists (regardless of the reference target). Both
callers (via reference.store.AddDigest) do check in advance, using
reference.store.Get, whether the digest reference exists before
calling AddDigest, but the reference store lock is released between
the two calls, so if another thread sets the reference in the meantime,
AddDigest may fail with
> Cannot overwrite digest ...
.
Handle this by checking that the pre-existing reference points at the
same image, i.e. that there is nothing to do, and succeeding immediately
in that case. This is even cheaper, avoids a reference.store.save() call.
(In principle, the same failure could have happened via
reference.store.AddTag, as
> Conflict: Tag %s is already set to image %s, if you want to replace it, please use -f option
but almost all callers (except for migrate/v1.Migrate, which is run
single-threaded anyway) set the "force" parameter of AddTag to true,
which makes the race invisible. This commit does not change the behavior
of that case, except for speeding it up by avoiding the
reference.store.save() call.)
The existing reference.store.Get checks are now, in a sense, redundant
as such, but their existence allows the callers to provide nice
context-dependent error messages, so this commit leaves them unchanged.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-09-06 17:24:06 -04:00
|
|
|
// Write the same values again; should silently succeed
|
|
|
|
if err = store.AddDigest(ref5.(reference.Canonical), testImageID2, false); err != nil {
|
|
|
|
t.Fatalf("error redundantly adding to store: %v", err)
|
|
|
|
}
|
2015-11-18 17:16:21 -05:00
|
|
|
|
|
|
|
// Attempt to overwrite with force == false
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref4, testImageID3, false); err == nil || !strings.HasPrefix(err.Error(), "Conflict:") {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("did not get expected error on overwrite attempt - got %v", err)
|
|
|
|
}
|
|
|
|
// Repeat to overwrite with force == true
|
2015-11-25 15:42:40 -05:00
|
|
|
if err = store.AddTag(ref4, testImageID3, true); err != nil {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("failed to force tag overwrite: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check references so far
|
|
|
|
id, err := store.Get(nameOnly)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID1 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err = store.Get(ref1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID1 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err = store.Get(ref2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID2 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID2.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err = store.Get(ref3)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID1 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err = store.Get(ref4)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID3 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID3.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err = store.Get(ref5)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
if id != testImageID2 {
|
|
|
|
t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID3.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get should return ErrDoesNotExist for a nonexistent repo
|
2017-01-25 19:54:18 -05:00
|
|
|
nonExistRepo, err := reference.ParseNormalizedNamed("username/nonexistrepo:latest")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
|
|
|
if _, err = store.Get(nonExistRepo); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Get")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get should return ErrDoesNotExist for a nonexistent tag
|
2017-01-25 19:54:18 -05:00
|
|
|
nonExistTag, err := reference.ParseNormalizedNamed("username/repo1:nonexist")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
|
|
|
if _, err = store.Get(nonExistTag); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Get")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check References
|
|
|
|
refs := store.References(testImageID1)
|
|
|
|
if len(refs) != 3 {
|
|
|
|
t.Fatal("unexpected number of references")
|
|
|
|
}
|
2015-12-07 20:55:35 -05:00
|
|
|
// Looking for the references in this order verifies that they are
|
|
|
|
// returned lexically sorted.
|
2015-11-18 17:16:21 -05:00
|
|
|
if refs[0].String() != ref3.String() {
|
|
|
|
t.Fatalf("unexpected reference: %v", refs[0].String())
|
|
|
|
}
|
|
|
|
if refs[1].String() != ref1.String() {
|
|
|
|
t.Fatalf("unexpected reference: %v", refs[1].String())
|
|
|
|
}
|
|
|
|
if refs[2].String() != nameOnly.String()+":latest" {
|
|
|
|
t.Fatalf("unexpected reference: %v", refs[2].String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check ReferencesByName
|
2017-01-25 19:54:18 -05:00
|
|
|
repoName, err := reference.ParseNormalizedNamed("username/repo1")
|
2015-11-18 17:16:21 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not parse reference: %v", err)
|
|
|
|
}
|
|
|
|
associations := store.ReferencesByName(repoName)
|
|
|
|
if len(associations) != 3 {
|
|
|
|
t.Fatal("unexpected number of associations")
|
|
|
|
}
|
2015-12-07 20:55:35 -05:00
|
|
|
// Looking for the associations in this order verifies that they are
|
|
|
|
// returned lexically sorted.
|
2015-11-18 17:16:21 -05:00
|
|
|
if associations[0].Ref.String() != ref3.String() {
|
|
|
|
t.Fatalf("unexpected reference: %v", associations[0].Ref.String())
|
|
|
|
}
|
2016-09-15 19:37:32 -04:00
|
|
|
if associations[0].ID != testImageID1 {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("unexpected reference: %v", associations[0].Ref.String())
|
|
|
|
}
|
|
|
|
if associations[1].Ref.String() != ref1.String() {
|
|
|
|
t.Fatalf("unexpected reference: %v", associations[1].Ref.String())
|
|
|
|
}
|
2016-09-15 19:37:32 -04:00
|
|
|
if associations[1].ID != testImageID1 {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("unexpected reference: %v", associations[1].Ref.String())
|
|
|
|
}
|
|
|
|
if associations[2].Ref.String() != ref2.String() {
|
|
|
|
t.Fatalf("unexpected reference: %v", associations[2].Ref.String())
|
|
|
|
}
|
2016-09-15 19:37:32 -04:00
|
|
|
if associations[2].ID != testImageID2 {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatalf("unexpected reference: %v", associations[2].Ref.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete should return ErrDoesNotExist for a nonexistent repo
|
|
|
|
if _, err = store.Delete(nonExistRepo); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Delete")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete should return ErrDoesNotExist for a nonexistent tag
|
|
|
|
if _, err = store.Delete(nonExistTag); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Delete")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete a few references
|
2017-09-11 14:55:05 -04:00
|
|
|
if deleted, err := store.Delete(ref1); err != nil || !deleted {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatal("Delete failed")
|
|
|
|
}
|
|
|
|
if _, err := store.Get(ref1); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Get")
|
|
|
|
}
|
2017-09-11 14:55:05 -04:00
|
|
|
if deleted, err := store.Delete(ref5); err != nil || !deleted {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatal("Delete failed")
|
|
|
|
}
|
|
|
|
if _, err := store.Get(ref5); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Get")
|
|
|
|
}
|
2017-09-11 14:55:05 -04:00
|
|
|
if deleted, err := store.Delete(nameOnly); err != nil || !deleted {
|
2015-11-18 17:16:21 -05:00
|
|
|
t.Fatal("Delete failed")
|
|
|
|
}
|
|
|
|
if _, err := store.Get(nameOnly); err != ErrDoesNotExist {
|
|
|
|
t.Fatal("Expected ErrDoesNotExist from Get")
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 15:42:40 -05:00
|
|
|
|
|
|
|
func TestInvalidTags(t *testing.T) {
|
2021-08-24 06:10:50 -04:00
|
|
|
tmpDir, err := os.MkdirTemp("", "tag-store-test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-11-25 15:42:40 -05:00
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
2017-08-17 18:43:36 -04:00
|
|
|
store, err := NewReferenceStore(filepath.Join(tmpDir, "repositories.json"))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-09-15 19:37:32 -04:00
|
|
|
id := digest.Digest("sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6")
|
2015-11-25 15:42:40 -05:00
|
|
|
|
|
|
|
// sha256 as repo name
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed("sha256:abc")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-11-25 15:42:40 -05:00
|
|
|
err = store.AddTag(ref, id, true)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, ""))
|
2015-11-25 15:42:40 -05:00
|
|
|
|
|
|
|
// setting digest as a tag
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err = reference.ParseNormalizedNamed("registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-11-25 15:42:40 -05:00
|
|
|
|
2017-09-08 18:00:14 -04:00
|
|
|
err = store.AddTag(ref, id, true)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, ""))
|
2015-11-25 15:42:40 -05:00
|
|
|
}
|