Browse code

integ-cli: Fix path problems in TestBuildRenamedDockerfile

`TestBuildRenamedDockerfile` tests hard-code unix-style
path building. Made use of `path/filepath` to make these
tests work on Windows as well.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>

Ahmet Alp Balkan authored on 2015/02/18 16:59:13
Showing 1 changed files
... ...
@@ -4556,7 +4556,7 @@ func TestBuildRenamedDockerfile(t *testing.T) {
4556 4556
 		t.Fatalf("test1 should have used Dockerfile, output:%s", out)
4557 4557
 	}
4558 4558
 
4559
-	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", "-f", "files/Dockerfile", "-t", "test2", ".")
4559
+	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", "-f", filepath.Join("files", "Dockerfile"), "-t", "test2", ".")
4560 4560
 	if err != nil {
4561 4561
 		t.Fatal(err)
4562 4562
 	}
... ...
@@ -4564,7 +4564,7 @@ func TestBuildRenamedDockerfile(t *testing.T) {
4564 4564
 		t.Fatalf("test2 should have used files/Dockerfile, output:%s", out)
4565 4565
 	}
4566 4566
 
4567
-	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", "--file=files/dFile", "-t", "test3", ".")
4567
+	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", fmt.Sprintf("--file=%s", filepath.Join("files", "dFile")), "-t", "test3", ".")
4568 4568
 	if err != nil {
4569 4569
 		t.Fatal(err)
4570 4570
 	}
... ...
@@ -4580,15 +4580,22 @@ func TestBuildRenamedDockerfile(t *testing.T) {
4580 4580
 		t.Fatalf("test4 should have used dFile, output:%s", out)
4581 4581
 	}
4582 4582
 
4583
-	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", "--file=/etc/passwd", "-t", "test5", ".")
4583
+	dirWithNoDockerfile, _ := ioutil.TempDir(os.TempDir(), "test5")
4584
+	nonDockerfileFile := filepath.Join(dirWithNoDockerfile, "notDockerfile")
4585
+	if _, err = os.Create(nonDockerfileFile); err != nil {
4586
+		t.Fatal(err)
4587
+	}
4588
+	out, _, err = dockerCmdInDir(t, ctx.Dir, "build", fmt.Sprintf("--file=%s", nonDockerfileFile), "-t", "test5", ".")
4589
+
4584 4590
 	if err == nil {
4585 4591
 		t.Fatalf("test5 was supposed to fail to find passwd")
4586 4592
 	}
4587
-	if !strings.Contains(out, "The Dockerfile (/etc/passwd) must be within the build context (.)") {
4588
-		t.Fatalf("test5 - wrong error message for passwd:%v", out)
4593
+
4594
+	if expected := fmt.Sprintf("The Dockerfile (%s) must be within the build context (.)", strings.Replace(nonDockerfileFile, `\`, `\\`, -1)); !strings.Contains(out, expected) {
4595
+		t.Fatalf("wrong error messsage:%v\nexpected to contain=%v", out, expected)
4589 4596
 	}
4590 4597
 
4591
-	out, _, err = dockerCmdInDir(t, ctx.Dir+"/files", "build", "-f", "../Dockerfile", "-t", "test6", "..")
4598
+	out, _, err = dockerCmdInDir(t, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test6", "..")
4592 4599
 	if err != nil {
4593 4600
 		t.Fatalf("test6 failed: %s", err)
4594 4601
 	}
... ...
@@ -4596,7 +4603,7 @@ func TestBuildRenamedDockerfile(t *testing.T) {
4596 4596
 		t.Fatalf("test6 should have used root Dockerfile, output:%s", out)
4597 4597
 	}
4598 4598
 
4599
-	out, _, err = dockerCmdInDir(t, filepath.Join(ctx.Dir, "files"), "build", "-f", ctx.Dir+"/files/Dockerfile", "-t", "test7", "..")
4599
+	out, _, err = dockerCmdInDir(t, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join(ctx.Dir, "files", "Dockerfile"), "-t", "test7", "..")
4600 4600
 	if err != nil {
4601 4601
 		t.Fatalf("test7 failed: %s", err)
4602 4602
 	}
... ...
@@ -4604,13 +4611,12 @@ func TestBuildRenamedDockerfile(t *testing.T) {
4604 4604
 		t.Fatalf("test7 should have used files Dockerfile, output:%s", out)
4605 4605
 	}
4606 4606
 
4607
-	out, _, err = dockerCmdInDir(t, ctx.Dir+"/files", "build", "-f", "../Dockerfile", "-t", "test8", ".")
4607
+	out, _, err = dockerCmdInDir(t, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test8", ".")
4608 4608
 	if err == nil || !strings.Contains(out, "must be within the build context") {
4609 4609
 		t.Fatalf("test8 should have failed with Dockerfile out of context: %s", err)
4610 4610
 	}
4611 4611
 
4612 4612
 	tmpDir := os.TempDir()
4613
-
4614 4613
 	out, _, err = dockerCmdInDir(t, tmpDir, "build", "-t", "test9", ctx.Dir)
4615 4614
 	if err != nil {
4616 4615
 		t.Fatalf("test9 - failed: %s", err)