isula-build/patch/0043-enhancement-add-go-test-for-RUN-panic-problem.patch
DCCooper 950f2f8ba2 isula-build:Sync upstream patches
Signed-off-by: DCCooper <1866858@gmail.com>
2021-03-03 19:29:30 +08:00

67 lines
1.9 KiB
Diff

From c0d4159d7719fb94b4b421415b8f367c6f61c68e Mon Sep 17 00:00:00 2001
From: DCCooper <1866858@gmail.com>
Date: Mon, 8 Feb 2021 10:22:33 +0800
Subject: [PATCH 02/10] enhancement: add go test for RUN panic problem
Signed-off-by: DCCooper <1866858@gmail.com>
---
builder/dockerfile/parser/parser_test.go | 18 ++++++++++++++----
.../testfiles/preprocess/run_with_directive | 2 ++
2 files changed, 16 insertions(+), 4 deletions(-)
create mode 100644 builder/dockerfile/parser/testfiles/preprocess/run_with_directive
diff --git a/builder/dockerfile/parser/parser_test.go b/builder/dockerfile/parser/parser_test.go
index f0cce1e9..3da5bea6 100644
--- a/builder/dockerfile/parser/parser_test.go
+++ b/builder/dockerfile/parser/parser_test.go
@@ -69,8 +69,9 @@ func TestPreProcess(t *testing.T) {
func TestFormat(t *testing.T) {
type testcase struct {
- name string
- expect int
+ name string
+ expect int
+ wantErr bool
}
var testcases = []testcase{
{
@@ -89,6 +90,10 @@ func TestFormat(t *testing.T) {
name: "yum_config",
expect: 8,
},
+ {
+ name: "run_with_directive",
+ wantErr: true,
+ },
}
for _, tc := range testcases {
@@ -103,8 +108,13 @@ func TestFormat(t *testing.T) {
d, err := newDirective(bytes.NewReader(buf.Bytes()))
assert.NilError(t, err)
lines, err := format(rows, d)
- assert.NilError(t, err)
- assert.Equal(t, len(lines), tc.expect)
+ if (err != nil) != tc.wantErr {
+ t.Errorf("Testing failed. Expected: %v, got: %v", tc.wantErr, err)
+ }
+ if !tc.wantErr {
+ assert.NilError(t, err, file)
+ assert.Equal(t, len(lines), tc.expect)
+ }
})
}
}
diff --git a/builder/dockerfile/parser/testfiles/preprocess/run_with_directive b/builder/dockerfile/parser/testfiles/preprocess/run_with_directive
new file mode 100644
index 00000000..3f3465d3
--- /dev/null
+++ b/builder/dockerfile/parser/testfiles/preprocess/run_with_directive
@@ -0,0 +1,2 @@
+FROM scratch
+RUN \
--
2.27.0