| ... | ... |
@@ -72,7 +72,7 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
| 72 | 72 |
builder.mergeConfig(config, img.Config) |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- if config.Cmd == nil {
|
|
| 75 |
+ if config.Cmd == nil || len(config.Cmd) == 0 {
|
|
| 76 | 76 |
return nil, fmt.Errorf("No command specified")
|
| 77 | 77 |
} |
| 78 | 78 |
|
| ... | ... |
@@ -253,14 +253,14 @@ func (graph *Graph) WalkAll(handler func(*Image)) error {
|
| 253 | 253 |
func (graph *Graph) ByParent() (map[string][]*Image, error) {
|
| 254 | 254 |
byParent := make(map[string][]*Image) |
| 255 | 255 |
err := graph.WalkAll(func(image *Image) {
|
| 256 |
- image, err := graph.Get(image.Parent) |
|
| 256 |
+ parent, err := graph.Get(image.Parent) |
|
| 257 | 257 |
if err != nil {
|
| 258 | 258 |
return |
| 259 | 259 |
} |
| 260 |
- if children, exists := byParent[image.Parent]; exists {
|
|
| 261 |
- byParent[image.Parent] = []*Image{image}
|
|
| 260 |
+ if children, exists := byParent[parent.Id]; exists {
|
|
| 261 |
+ byParent[parent.Id] = []*Image{image}
|
|
| 262 | 262 |
} else {
|
| 263 |
- byParent[image.Parent] = append(children, image) |
|
| 263 |
+ byParent[parent.Id] = append(children, image) |
|
| 264 | 264 |
} |
| 265 | 265 |
}) |
| 266 | 266 |
return byParent, err |
| ... | ... |
@@ -178,6 +178,10 @@ func (runtime *Runtime) LogToDisk(src *writeBroadcaster, dst string) error {
|
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
func (runtime *Runtime) Destroy(container *Container) error {
|
| 181 |
+ if container == nil {
|
|
| 182 |
+ return fmt.Errorf("The given container is <nil>")
|
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 181 | 185 |
element := runtime.getContainerElement(container.Id) |
| 182 | 186 |
if element == nil {
|
| 183 | 187 |
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id)
|
| ... | ... |
@@ -118,7 +118,10 @@ func TestRuntimeCreate(t *testing.T) {
|
| 118 | 118 |
if len(runtime.List()) != 0 {
|
| 119 | 119 |
t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
|
| 120 | 120 |
} |
| 121 |
- container, err := NewBuilder(runtime).Create(&Config{
|
|
| 121 |
+ |
|
| 122 |
+ builder := NewBuilder(runtime) |
|
| 123 |
+ |
|
| 124 |
+ container, err := builder.Create(&Config{
|
|
| 122 | 125 |
Image: GetTestImage(runtime).Id, |
| 123 | 126 |
Cmd: []string{"ls", "-al"},
|
| 124 | 127 |
}, |
| ... | ... |
@@ -157,6 +160,26 @@ func TestRuntimeCreate(t *testing.T) {
|
| 157 | 157 |
if !runtime.Exists(container.Id) {
|
| 158 | 158 |
t.Errorf("Exists() returned false for a newly created container")
|
| 159 | 159 |
} |
| 160 |
+ |
|
| 161 |
+ // Make sure crete with bad parameters returns an error |
|
| 162 |
+ _, err = builder.Create( |
|
| 163 |
+ &Config{
|
|
| 164 |
+ Image: GetTestImage(runtime).Id, |
|
| 165 |
+ }, |
|
| 166 |
+ ) |
|
| 167 |
+ if err == nil {
|
|
| 168 |
+ t.Fatal("Builder.Create should throw an error when Cmd is missing")
|
|
| 169 |
+ } |
|
| 170 |
+ |
|
| 171 |
+ _, err = builder.Create( |
|
| 172 |
+ &Config{
|
|
| 173 |
+ Image: GetTestImage(runtime).Id, |
|
| 174 |
+ Cmd: []string{},
|
|
| 175 |
+ }, |
|
| 176 |
+ ) |
|
| 177 |
+ if err == nil {
|
|
| 178 |
+ t.Fatal("Builder.Create should throw an error when Cmd is empty")
|
|
| 179 |
+ } |
|
| 160 | 180 |
} |
| 161 | 181 |
|
| 162 | 182 |
func TestDestroy(t *testing.T) {
|
| ... | ... |
@@ -442,7 +442,11 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
|
| 442 | 442 |
} |
| 443 | 443 |
|
| 444 | 444 |
func (k *KernelVersionInfo) String() string {
|
| 445 |
- return fmt.Sprintf("%d.%d.%d-%s", k.Kernel, k.Major, k.Minor, k.Flavor)
|
|
| 445 |
+ flavor := "" |
|
| 446 |
+ if len(k.Flavor) > 0 {
|
|
| 447 |
+ flavor = fmt.Sprintf("-%s", k.Flavor)
|
|
| 448 |
+ } |
|
| 449 |
+ return fmt.Sprintf("%d.%d.%d%s", k.Kernel, k.Major, k.Minor, flavor)
|
|
| 446 | 450 |
} |
| 447 | 451 |
|
| 448 | 452 |
// Compare two KernelVersionInfo struct. |