mirror of https://github.com/docker/docs.git
Merge pull request #552 from dotcloud/548-no_command_panic-fix
- Builder: Check the command existance prior create and add Unit tests for the case
This commit is contained in:
commit
f8dd04d567
|
@ -72,7 +72,7 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
||||||
builder.mergeConfig(config, img.Config)
|
builder.mergeConfig(config, img.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Cmd == nil {
|
if config.Cmd == nil || len(config.Cmd) == 0 {
|
||||||
return nil, fmt.Errorf("No command specified")
|
return nil, fmt.Errorf("No command specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,10 @@ func (runtime *Runtime) LogToDisk(src *writeBroadcaster, dst string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runtime *Runtime) Destroy(container *Container) error {
|
func (runtime *Runtime) Destroy(container *Container) error {
|
||||||
|
if container == nil {
|
||||||
|
return fmt.Errorf("The given container is <nil>")
|
||||||
|
}
|
||||||
|
|
||||||
element := runtime.getContainerElement(container.Id)
|
element := runtime.getContainerElement(container.Id)
|
||||||
if element == nil {
|
if element == nil {
|
||||||
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id)
|
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id)
|
||||||
|
|
|
@ -118,7 +118,10 @@ func TestRuntimeCreate(t *testing.T) {
|
||||||
if len(runtime.List()) != 0 {
|
if len(runtime.List()) != 0 {
|
||||||
t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
|
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,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
|
@ -157,6 +160,26 @@ func TestRuntimeCreate(t *testing.T) {
|
||||||
if !runtime.Exists(container.Id) {
|
if !runtime.Exists(container.Id) {
|
||||||
t.Errorf("Exists() returned false for a newly created container")
|
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) {
|
func TestDestroy(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue