dockerfile: nicer subtest cases in parser tests

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-04-14 20:46:40 -07:00
parent 7c0493de8d
commit f2307db707
1 changed files with 24 additions and 20 deletions

View File

@ -31,6 +31,7 @@ func getDirs(t *testing.T, dir string) []string {
func TestParseErrorCases(t *testing.T) {
for _, dir := range getDirs(t, negativeTestDir) {
t.Run(dir, func(t *testing.T) {
dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile")
df, err := os.Open(dockerfile)
@ -39,11 +40,13 @@ func TestParseErrorCases(t *testing.T) {
_, err = Parse(df)
assert.Check(t, is.ErrorContains(err, ""), dockerfile)
})
}
}
func TestParseCases(t *testing.T) {
for _, dir := range getDirs(t, testDir) {
t.Run(dir, func(t *testing.T) {
dockerfile := filepath.Join(testDir, dir, "Dockerfile")
resultfile := filepath.Join(testDir, dir, "result")
@ -62,6 +65,7 @@ func TestParseCases(t *testing.T) {
content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1)
}
assert.Check(t, is.Equal(result.AST.Dump()+"\n", string(content)), "In "+dockerfile)
})
}
}