2013-11-09 14:47:32 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"export_path": "foo",
|
|
|
|
"image": "bar",
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
}
|
2013-11-09 14:47:32 -05:00
|
|
|
|
2013-11-09 20:07:14 -05:00
|
|
|
func testConfigStruct(t *testing.T) *Config {
|
|
|
|
c, warns, errs := NewConfig(testConfig())
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", len(warns))
|
|
|
|
}
|
|
|
|
if errs != nil {
|
|
|
|
t.Fatalf("bad: %#v", errs)
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
|
|
|
|
return c
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigPrepare_exportPath(t *testing.T) {
|
2013-11-09 20:07:14 -05:00
|
|
|
raw := testConfig()
|
2013-11-09 14:47:32 -05:00
|
|
|
|
|
|
|
// No export path
|
2013-11-09 20:07:14 -05:00
|
|
|
delete(raw, "export_path")
|
|
|
|
_, warns, errs := NewConfig(raw)
|
2013-11-09 14:47:32 -05:00
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
if errs == nil {
|
|
|
|
t.Fatal("should error")
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Good export path
|
2013-11-09 20:07:14 -05:00
|
|
|
raw["export_path"] = "good"
|
|
|
|
_, warns, errs = NewConfig(raw)
|
2013-11-09 14:47:32 -05:00
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
if errs != nil {
|
|
|
|
t.Fatalf("bad: %s", errs)
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigPrepare_image(t *testing.T) {
|
2013-11-09 20:07:14 -05:00
|
|
|
raw := testConfig()
|
2013-11-09 14:47:32 -05:00
|
|
|
|
|
|
|
// No image
|
2013-11-09 20:07:14 -05:00
|
|
|
delete(raw, "image")
|
|
|
|
_, warns, errs := NewConfig(raw)
|
2013-11-09 14:47:32 -05:00
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
if errs == nil {
|
|
|
|
t.Fatal("should error")
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Good image
|
2013-11-09 20:07:14 -05:00
|
|
|
raw["image"] = "path"
|
|
|
|
_, warns, errs = NewConfig(raw)
|
2013-11-09 14:47:32 -05:00
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
2013-11-09 20:07:14 -05:00
|
|
|
if errs != nil {
|
|
|
|
t.Fatalf("bad: %s", errs)
|
2013-11-09 14:47:32 -05:00
|
|
|
}
|
|
|
|
}
|