Refactor tests

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
Silvin Lubecki 2018-06-25 11:09:38 +02:00
parent cc26da94ed
commit 38056740d6
1 changed files with 30 additions and 39 deletions

View File

@ -1417,58 +1417,49 @@ networks:
} }
func TestLoadInit(t *testing.T) { func TestLoadInit(t *testing.T) {
booleanFalse := false
booleanTrue := true booleanTrue := true
config, err := loadYAML(` booleanFalse := false
var testcases = []struct {
doc string
yaml string
init *bool
}{
{
doc: "no init defined",
yaml: `
version: '3.7' version: '3.7'
services: services:
foo: foo:
image: alpine`) image: alpine`,
assert.NilError(t, err) },
assert.Check(t, is.DeepEqual(config, &types.Config{
Filename: "filename.yml",
Version: "3.7",
Services: types.Services{
{ {
Name: "foo", doc: "has true init",
Image: "alpine", yaml: `
},
},
}, cmpopts.EquateEmpty()))
config, err = loadYAML(`
version: '3.7' version: '3.7'
services: services:
foo: foo:
image: alpine image: alpine
init: true`) init: true`,
assert.NilError(t, err) init: &booleanTrue,
assert.Check(t, is.DeepEqual(config, &types.Config{ },
Filename: "filename.yml",
Version: "3.7",
Services: types.Services{
{ {
Name: "foo", doc: "has false init",
Image: "alpine", yaml: `
Init: &booleanTrue,
},
},
}, cmpopts.EquateEmpty()))
config, err = loadYAML(`
version: '3.7' version: '3.7'
services: services:
foo: foo:
image: alpine image: alpine
init: false`) init: false`,
init: &booleanFalse,
},
}
for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) {
config, err := loadYAML(testcase.yaml)
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(config, &types.Config{ assert.Check(t, is.Len(config.Services, 1))
Filename: "filename.yml", assert.Check(t, is.DeepEqual(config.Services[0].Init, testcase.init))
Version: "3.7", })
Services: types.Services{ }
{
Name: "foo",
Image: "alpine",
Init: &booleanFalse,
},
},
}, cmpopts.EquateEmpty()))
} }