Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
| ... | ... |
@@ -8,10 +8,15 @@ package parser |
| 8 | 8 |
|
| 9 | 9 |
import ( |
| 10 | 10 |
"encoding/json" |
| 11 |
+ "errors" |
|
| 11 | 12 |
"strconv" |
| 12 | 13 |
"strings" |
| 13 | 14 |
) |
| 14 | 15 |
|
| 16 |
+var ( |
|
| 17 |
+ dockerFileErrJSONNesting = errors.New("You may not nest arrays in Dockerfile statements.")
|
|
| 18 |
+) |
|
| 19 |
+ |
|
| 15 | 20 |
// ignore the current argument. This will still leave a command parsed, but |
| 16 | 21 |
// will not incorporate the arguments into the ast. |
| 17 | 22 |
func parseIgnore(rest string) (*Node, error) {
|
| ... | ... |
@@ -86,6 +91,8 @@ func parseJSON(rest string) (*Node, error) {
|
| 86 | 86 |
|
| 87 | 87 |
for _, str := range myJson {
|
| 88 | 88 |
switch str.(type) {
|
| 89 |
+ case []interface{}:
|
|
| 90 |
+ return nil, dockerFileErrJSONNesting |
|
| 89 | 91 |
case float64: |
| 90 | 92 |
str = strconv.FormatFloat(str.(float64), 'G', -1, 64) |
| 91 | 93 |
} |
| ... | ... |
@@ -110,6 +117,8 @@ func parseMaybeJSON(rest string) (*Node, error) {
|
| 110 | 110 |
node, err := parseJSON(rest) |
| 111 | 111 |
if err == nil {
|
| 112 | 112 |
return node, nil |
| 113 |
+ } else if err == dockerFileErrJSONNesting {
|
|
| 114 |
+ return nil, err |
|
| 113 | 115 |
} |
| 114 | 116 |
} |
| 115 | 117 |
|
| ... | ... |
@@ -8,9 +8,10 @@ import ( |
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 | 10 |
const testDir = "testfiles" |
| 11 |
+const negativeTestDir = "testfiles-negative" |
|
| 11 | 12 |
|
| 12 |
-func TestTestData(t *testing.T) {
|
|
| 13 |
- f, err := os.Open(testDir) |
|
| 13 |
+func getDirs(t *testing.T, dir string) []os.FileInfo {
|
|
| 14 |
+ f, err := os.Open(dir) |
|
| 14 | 15 |
if err != nil {
|
| 15 | 16 |
t.Fatal(err) |
| 16 | 17 |
} |
| ... | ... |
@@ -22,7 +23,29 @@ func TestTestData(t *testing.T) {
|
| 22 | 22 |
t.Fatal(err) |
| 23 | 23 |
} |
| 24 | 24 |
|
| 25 |
- for _, dir := range dirs {
|
|
| 25 |
+ return dirs |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+func TestTestNegative(t *testing.T) {
|
|
| 29 |
+ for _, dir := range getDirs(t, negativeTestDir) {
|
|
| 30 |
+ dockerfile := filepath.Join(negativeTestDir, dir.Name(), "Dockerfile") |
|
| 31 |
+ |
|
| 32 |
+ df, err := os.Open(dockerfile) |
|
| 33 |
+ if err != nil {
|
|
| 34 |
+ t.Fatalf("Dockerfile missing for %s: %s", dir.Name(), err.Error())
|
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ _, err = Parse(df) |
|
| 38 |
+ if err == nil {
|
|
| 39 |
+ t.Fatalf("No error parsing broken dockerfile for %s: %s", dir.Name(), err.Error())
|
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ df.Close() |
|
| 43 |
+ } |
|
| 44 |
+} |
|
| 45 |
+ |
|
| 46 |
+func TestTestData(t *testing.T) {
|
|
| 47 |
+ for _, dir := range getDirs(t, testDir) {
|
|
| 26 | 48 |
dockerfile := filepath.Join(testDir, dir.Name(), "Dockerfile") |
| 27 | 49 |
resultfile := filepath.Join(testDir, dir.Name(), "result") |
| 28 | 50 |
|