From f2307db707d7dec5f7764c3dbb7c74f7e3e4d783 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 14 Apr 2020 20:46:40 -0700 Subject: [PATCH] dockerfile: nicer subtest cases in parser tests Signed-off-by: Tonis Tiigi --- frontend/dockerfile/parser/parser_test.go | 44 ++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/frontend/dockerfile/parser/parser_test.go b/frontend/dockerfile/parser/parser_test.go index 4e076324..ce4a1040 100644 --- a/frontend/dockerfile/parser/parser_test.go +++ b/frontend/dockerfile/parser/parser_test.go @@ -31,37 +31,41 @@ func getDirs(t *testing.T, dir string) []string { func TestParseErrorCases(t *testing.T) { for _, dir := range getDirs(t, negativeTestDir) { - dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile") + t.Run(dir, func(t *testing.T) { + dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile") - df, err := os.Open(dockerfile) - assert.NilError(t, err, dockerfile) - defer df.Close() + df, err := os.Open(dockerfile) + assert.NilError(t, err, dockerfile) + defer df.Close() - _, err = Parse(df) - assert.Check(t, is.ErrorContains(err, ""), dockerfile) + _, err = Parse(df) + assert.Check(t, is.ErrorContains(err, ""), dockerfile) + }) } } func TestParseCases(t *testing.T) { for _, dir := range getDirs(t, testDir) { - dockerfile := filepath.Join(testDir, dir, "Dockerfile") - resultfile := filepath.Join(testDir, dir, "result") + t.Run(dir, func(t *testing.T) { + dockerfile := filepath.Join(testDir, dir, "Dockerfile") + resultfile := filepath.Join(testDir, dir, "result") - df, err := os.Open(dockerfile) - assert.NilError(t, err, dockerfile) - defer df.Close() + df, err := os.Open(dockerfile) + assert.NilError(t, err, dockerfile) + defer df.Close() - result, err := Parse(df) - assert.NilError(t, err, dockerfile) + result, err := Parse(df) + assert.NilError(t, err, dockerfile) - content, err := ioutil.ReadFile(resultfile) - assert.NilError(t, err, resultfile) + content, err := ioutil.ReadFile(resultfile) + assert.NilError(t, err, resultfile) - if runtime.GOOS == "windows" { - // CRLF --> CR to match Unix behavior - content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1) - } - assert.Check(t, is.Equal(result.AST.Dump()+"\n", string(content)), "In "+dockerfile) + if runtime.GOOS == "windows" { + // CRLF --> CR to match Unix behavior + content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1) + } + assert.Check(t, is.Equal(result.AST.Dump()+"\n", string(content)), "In "+dockerfile) + }) } }