فهرست منبع

Get list of Dockerfile cmds from builder so we can be smarted in our tests

Signed-off-by: Doug Davis <dug@us.ibm.com>
Doug Davis 10 سال پیش
والد
کامیت
d1e9d07c1b
2فایلهای تغییر یافته به همراه29 افزوده شده و 27 حذف شده
  1. 6 4
      builder/evaluator.go
  2. 23 23
      integration-cli/docker_cli_build_test.go

+ 6 - 4
builder/evaluator.go

@@ -54,10 +54,12 @@ var replaceEnvAllowed = map[string]struct{}{
 	"user":    {},
 	"user":    {},
 }
 }
 
 
-var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
+// EvaluateTable is public so that we can get the list of Dockerfile
+// commands from within the test cases
+var EvaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
 
 
 func init() {
 func init() {
-	evaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{
+	EvaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{
 		"env":        env,
 		"env":        env,
 		"maintainer": maintainer,
 		"maintainer": maintainer,
 		"add":        add,
 		"add":        add,
@@ -224,7 +226,7 @@ func (b *Builder) readDockerfile(origFile string) error {
 // Child[Node, Node, Node] where Child is from parser.Node.Children and each
 // Child[Node, Node, Node] where Child is from parser.Node.Children and each
 // node comes from parser.Node.Next. This forms a "line" with a statement and
 // node comes from parser.Node.Next. This forms a "line" with a statement and
 // arguments and we process them in this normalized form by hitting
 // arguments and we process them in this normalized form by hitting
-// evaluateTable with the leaf nodes of the command and the Builder object.
+// EvaluateTable with the leaf nodes of the command and the Builder object.
 //
 //
 // ONBUILD is a special case; in this case the parser will emit:
 // ONBUILD is a special case; in this case the parser will emit:
 // Child[Node, Child[Node, Node...]] where the first node is the literal
 // Child[Node, Child[Node, Node...]] where the first node is the literal
@@ -280,7 +282,7 @@ func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
 
 
 	// XXX yes, we skip any cmds that are not valid; the parser should have
 	// XXX yes, we skip any cmds that are not valid; the parser should have
 	// picked these out already.
 	// picked these out already.
-	if f, ok := evaluateTable[cmd]; ok {
+	if f, ok := EvaluateTable[cmd]; ok {
 		return f(b, strList, attrs, original)
 		return f(b, strList, attrs, original)
 	}
 	}
 
 

+ 23 - 23
integration-cli/docker_cli_build_test.go

@@ -19,6 +19,7 @@ import (
 	"text/template"
 	"text/template"
 	"time"
 	"time"
 
 
+	"github.com/docker/docker/builder"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 )
 )
 
 
@@ -4726,9 +4727,9 @@ func TestBuildSpaces(t *testing.T) {
 
 
 	name := "testspaces"
 	name := "testspaces"
 	defer deleteImages(name)
 	defer deleteImages(name)
-	ctx, err := fakeContext("FROM busybox\nRUN\n",
+	ctx, err := fakeContext("FROM busybox\nCOPY\n",
 		map[string]string{
 		map[string]string{
-			"Dockerfile": "FROM busybox\nRUN\n",
+			"Dockerfile": "FROM busybox\nCOPY\n",
 		})
 		})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -4739,7 +4740,7 @@ func TestBuildSpaces(t *testing.T) {
 		t.Fatal("Build 1 was supposed to fail, but didn't")
 		t.Fatal("Build 1 was supposed to fail, but didn't")
 	}
 	}
 
 
-	ctx.Add("Dockerfile", "FROM busybox\nRUN    ")
+	ctx.Add("Dockerfile", "FROM busybox\nCOPY    ")
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 		t.Fatal("Build 2 was supposed to fail, but didn't")
 		t.Fatal("Build 2 was supposed to fail, but didn't")
 	}
 	}
@@ -4753,7 +4754,7 @@ func TestBuildSpaces(t *testing.T) {
 		t.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", err1, err2)
 		t.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", err1, err2)
 	}
 	}
 
 
-	ctx.Add("Dockerfile", "FROM busybox\n   RUN")
+	ctx.Add("Dockerfile", "FROM busybox\n   COPY")
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 		t.Fatal("Build 3 was supposed to fail, but didn't")
 		t.Fatal("Build 3 was supposed to fail, but didn't")
 	}
 	}
@@ -4767,7 +4768,7 @@ func TestBuildSpaces(t *testing.T) {
 		t.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", err1, err2)
 		t.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", err1, err2)
 	}
 	}
 
 
-	ctx.Add("Dockerfile", "FROM busybox\n   RUN    ")
+	ctx.Add("Dockerfile", "FROM busybox\n   COPY    ")
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 	if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil {
 		t.Fatal("Build 4 was supposed to fail, but didn't")
 		t.Fatal("Build 4 was supposed to fail, but didn't")
 	}
 	}
@@ -4824,27 +4825,28 @@ func TestBuildVolumeFileExistsinContainer(t *testing.T) {
 }
 }
 
 
 func TestBuildMissingArgs(t *testing.T) {
 func TestBuildMissingArgs(t *testing.T) {
-	// test to make sure these cmds w/o any args will generate an error
-	// Notice some commands are missing because its ok for them to
-	// not have any args - like: CMD, RUN, ENTRYPOINT
-	cmds := []string{
-		"ADD",
-		"COPY",
-		"ENV",
-		"EXPOSE",
-		"FROM",
-		"MAINTAINER",
-		"ONBUILD",
-		"USER",
-		"VOLUME",
-		"WORKDIR",
+	// Test to make sure that all Dockerfile commands (except the ones listed
+	// in skipCmds) will generate an error if no args are provided.
+	// Note: INSERT is deprecated so we exclude it because of that.
+
+	skipCmds := map[string]struct{}{
+		"CMD":        {},
+		"RUN":        {},
+		"ENTRYPOINT": {},
+		"INSERT":     {},
 	}
 	}
 
 
 	defer deleteAllContainers()
 	defer deleteAllContainers()
 
 
-	for _, cmd := range cmds {
+	for cmd := range builder.EvaluateTable {
 		var dockerfile string
 		var dockerfile string
 
 
+		cmd = strings.ToUpper(cmd)
+
+		if _, ok := skipCmds[cmd]; ok {
+			continue
+		}
+
 		if cmd == "FROM" {
 		if cmd == "FROM" {
 			dockerfile = cmd
 			dockerfile = cmd
 		} else {
 		} else {
@@ -4859,13 +4861,11 @@ func TestBuildMissingArgs(t *testing.T) {
 		defer ctx.Close()
 		defer ctx.Close()
 		var out string
 		var out string
 		if out, err = buildImageFromContext("args", ctx, true); err == nil {
 		if out, err = buildImageFromContext("args", ctx, true); err == nil {
-			t.Fatalf("%s was supposed to fail:%s", cmd, out)
+			t.Fatalf("%s was supposed to fail. Out:%s", cmd, out)
 		}
 		}
 		if !strings.Contains(err.Error(), cmd+" requires") {
 		if !strings.Contains(err.Error(), cmd+" requires") {
 			t.Fatalf("%s returned the wrong type of error:%s", cmd, err)
 			t.Fatalf("%s returned the wrong type of error:%s", cmd, err)
 		}
 		}
-
-		ctx.Close()
 	}
 	}
 
 
 	logDone("build - verify missing args")
 	logDone("build - verify missing args")