mirror of https://github.com/docker/docs.git
Merge pull request #799 from dotcloud/691-run_id-feature
* Runtime: allow docker run <name>:<id>
This commit is contained in:
commit
30fb45c494
|
@ -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 {
|
||||
|
|
10
tags.go
10
tags.go
|
@ -197,14 +197,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 strings.HasPrefix(revision, tagOrId) {
|
||||
return store.graph.Get(revision)
|
||||
}
|
||||
}
|
||||
if revision, exists := repo[tagOrId]; exists {
|
||||
return store.graph.Get(revision)
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue