From d26a3b37a6a8d42b9e7cb7486b928170c43e052e Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 3 Jun 2013 20:00:15 +0000 Subject: [PATCH 1/2] allow docker run : --- tags.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tags.go b/tags.go index 5bc2978e09..140182890d 100644 --- a/tags.go +++ b/tags.go @@ -151,14 +151,20 @@ func (store *TagStore) Get(repoName string) (Repository, error) { return nil, nil } -func (store *TagStore) GetImage(repoName, tag string) (*Image, error) { +func (store *TagStore) GetImage(repoName, tagOrId string) (*Image, error) { repo, err := store.Get(repoName) if err != nil { return nil, err } else if repo == nil { return nil, nil } - if revision, exists := repo[tag]; exists { + //go through all the tags, to see if tag is in fact an ID + for _, revision := range repo { + if utils.TruncateId(revision) == tagOrId { + return store.graph.Get(revision) + } + } + if revision, exists := repo[tagOrId]; exists { return store.graph.Get(revision) } return nil, nil From 45a8945746a205ea513efc17bb242c63362c79a9 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 13 Jun 2013 13:17:56 +0000 Subject: [PATCH 2/2] added test --- runtime_test.go | 2 +- tags.go | 2 +- tags_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tags_test.go diff --git a/runtime_test.go b/runtime_test.go index 1190510279..eea69aa5dc 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -17,7 +17,7 @@ import ( ) const unitTestImageName string = "docker-ut" - +const unitTestImageId string = "e9aa60c60128cad1" const unitTestStoreBase string = "/var/lib/docker/unit-tests" func nuke(runtime *Runtime) error { diff --git a/tags.go b/tags.go index 140182890d..7133649f6e 100644 --- a/tags.go +++ b/tags.go @@ -160,7 +160,7 @@ func (store *TagStore) GetImage(repoName, tagOrId string) (*Image, error) { } //go through all the tags, to see if tag is in fact an ID for _, revision := range repo { - if utils.TruncateId(revision) == tagOrId { + if strings.HasPrefix(revision, tagOrId) { return store.graph.Get(revision) } } diff --git a/tags_test.go b/tags_test.go new file mode 100644 index 0000000000..5d03275909 --- /dev/null +++ b/tags_test.go @@ -0,0 +1,49 @@ +package docker + +import ( + "testing" +) + +func TestLookupImage(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil { + t.Fatal(err) + } else if img == nil { + t.Errorf("Expected 1 image, none found") + } + + if img, err := runtime.repositories.LookupImage(unitTestImageName + ":" + DEFAULT_TAG); err != nil { + t.Fatal(err) + } else if img == nil { + t.Errorf("Expected 1 image, none found") + } + + if img, err := runtime.repositories.LookupImage(unitTestImageName + ":" + "fail"); err == nil { + t.Errorf("Expected error, none found") + } else if img != nil { + t.Errorf("Expected 0 image, 1 found") + } + + if img, err := runtime.repositories.LookupImage("fail:fail"); err == nil { + t.Errorf("Expected error, none found") + } else if img != nil { + t.Errorf("Expected 0 image, 1 found") + } + + if img, err := runtime.repositories.LookupImage(unitTestImageId); err != nil { + t.Fatal(err) + } else if img == nil { + t.Errorf("Expected 1 image, none found") + } + + if img, err := runtime.repositories.LookupImage(unitTestImageName + ":" + unitTestImageId); err != nil { + t.Fatal(err) + } else if img == nil { + t.Errorf("Expected 1 image, none found") + } +}