Browse code

Windows: Fix failing unit tests

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/04/07 05:42:15
Showing 2 changed files
... ...
@@ -174,7 +174,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (absContextDir, rel
174 174
 // the dockerfile in that context directory, and a non-nil error on success.
175 175
 func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDir, relDockerfile string, err error) {
176 176
 	if absContextDir, err = filepath.Abs(givenContextDir); err != nil {
177
-		return "", "", fmt.Errorf("unable to get absolute context directory: %v", err)
177
+		return "", "", fmt.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err)
178 178
 	}
179 179
 
180 180
 	// The context dir might be a symbolic link, so follow it to the actual
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"io/ioutil"
8 8
 	"os"
9 9
 	"path/filepath"
10
+	"runtime"
10 11
 	"strings"
11 12
 	"testing"
12 13
 
... ...
@@ -53,7 +54,6 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) strin
53 53
 	contextDir := prepare(t)
54 54
 
55 55
 	defer os.RemoveAll(contextDir)
56
-
57 56
 	err := ValidateContextDirectory(contextDir, excludes)
58 57
 
59 58
 	if err != nil {
... ...
@@ -166,8 +166,7 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
166 166
 	if err != nil {
167 167
 		t.Fatalf("Error when changing directory to %s: %s", contextDir, err)
168 168
 	}
169
-
170
-	absContextDir, relDockerfile, err := GetContextFromLocalDir("", "")
169
+	absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
171 170
 
172 171
 	if err != nil {
173 172
 		t.Fatalf("Error when getting context from local dir: %s", err)
... ...
@@ -400,6 +399,14 @@ func TestGetContextFromReaderTar(t *testing.T) {
400 400
 }
401 401
 
402 402
 func TestValidateContextDirectoryEmptyContext(t *testing.T) {
403
+	// This isn't a valid test on Windows. See https://play.golang.org/p/RR6z6jxR81.
404
+	// The test will ultimately end up calling filepath.Abs(""). On Windows,
405
+	// golang will error. On Linux, golang will return /. Due to there being
406
+	// drive letters on Windows, this is probably the correct behaviour for
407
+	// Windows.
408
+	if runtime.GOOS == "windows" {
409
+		t.Skip("Invalid test on Windows")
410
+	}
403 411
 	testValidateContextDirectory(t, prepareEmpty, []string{})
404 412
 }
405 413