1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Docker: Fixed an issue with container unmarshaling which prevented

docker.restore() to work properly.
This commit is contained in:
Andrea Luzzardi 2013-01-25 14:09:21 -08:00
parent 9b300272df
commit 2193b0c954
3 changed files with 34 additions and 2 deletions

View file

@ -70,7 +70,7 @@ func loadContainer(containerPath string) (*Container, error) {
if err != nil {
return nil, err
}
var container *Container
container := &Container{}
if err := json.Unmarshal(data, container); err != nil {
return nil, err
}

View file

@ -4,6 +4,7 @@ import (
"container/list"
"fmt"
"io/ioutil"
"log"
"os"
"path"
)
@ -82,7 +83,7 @@ func (docker *Docker) restore() error {
for _, v := range dir {
container, err := loadContainer(path.Join(docker.repository, v.Name()))
if err != nil {
fmt.Errorf("Failed to load %v: %v", v.Name(), err)
log.Printf("Failed to load container %v: %v", v.Name(), err)
continue
}
docker.containers.PushBack(container)

View file

@ -173,3 +173,34 @@ func TestGet(t *testing.T) {
}
}
func TestRestore(t *testing.T) {
root, err := ioutil.TempDir("", "docker-test")
if err != nil {
t.Fatal(err)
}
docker, err := NewFromDirectory(root)
if err != nil {
t.Fatal(err)
}
container, err := docker.Create(
"test",
"ls",
[]string{"-al"},
[]string{"/var/lib/docker/images/ubuntu"},
&Config{},
)
if len(docker.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker.List()))
}
defer docker.Destroy(container)
docker2, err := NewFromDirectory(root)
if err != nil {
t.Fatal(err)
}
if len(docker2.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker2.List()))
}
}