From 23c5c130148985e3e527fa799beb45326ac791a9 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 6 May 2013 21:31:59 -0700 Subject: [PATCH 1/3] fix ByParent --- graph.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/graph.go b/graph.go index 21d9d9407c..9a8fd1b3cb 100644 --- a/graph.go +++ b/graph.go @@ -253,14 +253,14 @@ func (graph *Graph) WalkAll(handler func(*Image)) error { func (graph *Graph) ByParent() (map[string][]*Image, error) { byParent := make(map[string][]*Image) err := graph.WalkAll(func(image *Image) { - image, err := graph.Get(image.Parent) + parent, err := graph.Get(image.Parent) if err != nil { return } - if children, exists := byParent[image.Parent]; exists { - byParent[image.Parent] = []*Image{image} + if children, exists := byParent[parent.Id]; exists { + byParent[parent.Id] = []*Image{image} } else { - byParent[image.Parent] = append(children, image) + byParent[parent.Id] = append(children, image) } }) return byParent, err From d2eb2455a1fc379dbac94d651b0785b631b84add Mon Sep 17 00:00:00 2001 From: unclejack Date: Tue, 7 May 2013 20:57:21 +0300 Subject: [PATCH 2/3] kernel version - don't show the dash if flavor is empty --- utils.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 2d54ef4c6a..217fad0322 100644 --- a/utils.go +++ b/utils.go @@ -425,7 +425,11 @@ func GetKernelVersion() (*KernelVersionInfo, error) { } func (k *KernelVersionInfo) String() string { - return fmt.Sprintf("%d.%d.%d-%s", k.Kernel, k.Major, k.Minor, k.Flavor) + flavor := "" + if len(k.Flavor) > 0 { + flavor = fmt.Sprintf("-%s", k.Flavor) + } + return fmt.Sprintf("%d.%d.%d%s", k.Kernel, k.Major, k.Minor, flavor) } // Compare two KernelVersionInfo struct. From 42b1ea4889cd61790f81001ada5deac9354be378 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 7 May 2013 11:18:13 -0700 Subject: [PATCH 3/3] Check the command existance prior create and add Unit tests for the case --- builder.go | 2 +- runtime.go | 4 ++++ runtime_test.go | 25 ++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/builder.go b/builder.go index e835c6d390..d8a22ac3c8 100644 --- a/builder.go +++ b/builder.go @@ -72,7 +72,7 @@ func (builder *Builder) Create(config *Config) (*Container, error) { builder.mergeConfig(config, img.Config) } - if config.Cmd == nil { + if config.Cmd == nil || len(config.Cmd) == 0 { return nil, fmt.Errorf("No command specified") } diff --git a/runtime.go b/runtime.go index 5958aa1811..7db3b40325 100644 --- a/runtime.go +++ b/runtime.go @@ -178,6 +178,10 @@ func (runtime *Runtime) LogToDisk(src *writeBroadcaster, dst string) error { } func (runtime *Runtime) Destroy(container *Container) error { + if container == nil { + return fmt.Errorf("The given container is ") + } + element := runtime.getContainerElement(container.Id) if element == nil { return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id) diff --git a/runtime_test.go b/runtime_test.go index 8e21f57bc5..68e1213497 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -118,7 +118,10 @@ func TestRuntimeCreate(t *testing.T) { if len(runtime.List()) != 0 { t.Errorf("Expected 0 containers, %v found", len(runtime.List())) } - container, err := NewBuilder(runtime).Create(&Config{ + + builder := NewBuilder(runtime) + + container, err := builder.Create(&Config{ Image: GetTestImage(runtime).Id, Cmd: []string{"ls", "-al"}, }, @@ -157,6 +160,26 @@ func TestRuntimeCreate(t *testing.T) { if !runtime.Exists(container.Id) { t.Errorf("Exists() returned false for a newly created container") } + + // Make sure crete with bad parameters returns an error + _, err = builder.Create( + &Config{ + Image: GetTestImage(runtime).Id, + }, + ) + if err == nil { + t.Fatal("Builder.Create should throw an error when Cmd is missing") + } + + _, err = builder.Create( + &Config{ + Image: GetTestImage(runtime).Id, + Cmd: []string{}, + }, + ) + if err == nil { + t.Fatal("Builder.Create should throw an error when Cmd is empty") + } } func TestDestroy(t *testing.T) {