From ccd0da908ac2b0743ca2c8e80c589295fd3b2563 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 6 Apr 2016 13:42:15 -0700 Subject: [PATCH] Windows: Fix failing unit tests Signed-off-by: John Howard --- builder/context.go | 2 +- builder/context_test.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/builder/context.go b/builder/context.go index 53a90f1be2..1b6e9d04b0 100644 --- a/builder/context.go +++ b/builder/context.go @@ -174,7 +174,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (absContextDir, rel // the dockerfile in that context directory, and a non-nil error on success. func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDir, relDockerfile string, err error) { if absContextDir, err = filepath.Abs(givenContextDir); err != nil { - return "", "", fmt.Errorf("unable to get absolute context directory: %v", err) + return "", "", fmt.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err) } // The context dir might be a symbolic link, so follow it to the actual diff --git a/builder/context_test.go b/builder/context_test.go index cceca025a1..3100c34079 100644 --- a/builder/context_test.go +++ b/builder/context_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strings" "testing" @@ -53,7 +54,6 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) strin contextDir := prepare(t) defer os.RemoveAll(contextDir) - err := ValidateContextDirectory(contextDir, excludes) if err != nil { @@ -166,8 +166,7 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { if err != nil { t.Fatalf("Error when changing directory to %s: %s", contextDir, err) } - - absContextDir, relDockerfile, err := GetContextFromLocalDir("", "") + absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") if err != nil { t.Fatalf("Error when getting context from local dir: %s", err) @@ -400,6 +399,14 @@ func TestGetContextFromReaderTar(t *testing.T) { } func TestValidateContextDirectoryEmptyContext(t *testing.T) { + // This isn't a valid test on Windows. See https://play.golang.org/p/RR6z6jxR81. + // The test will ultimately end up calling filepath.Abs(""). On Windows, + // golang will error. On Linux, golang will return /. Due to there being + // drive letters on Windows, this is probably the correct behaviour for + // Windows. + if runtime.GOOS == "windows" { + t.Skip("Invalid test on Windows") + } testValidateContextDirectory(t, prepareEmpty, []string{}) }