|
@@ -9,6 +9,7 @@ import (
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"reflect"
|
|
|
+ "runtime"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
@@ -76,6 +77,11 @@ func TestCheckoutGit(t *testing.T) {
|
|
|
}
|
|
|
defer os.RemoveAll(root)
|
|
|
|
|
|
+ eol := "\n"
|
|
|
+ if runtime.GOOS == "windows" {
|
|
|
+ eol = "\r\n"
|
|
|
+ }
|
|
|
+
|
|
|
gitDir := filepath.Join(root, "repo")
|
|
|
_, err = git("init", gitDir)
|
|
|
if err != nil {
|
|
@@ -103,12 +109,14 @@ func TestCheckoutGit(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ if runtime.GOOS != "windows" {
|
|
|
+ if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
|
|
|
- if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
|
|
|
- t.Fatal(err)
|
|
|
+ if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil {
|
|
@@ -143,24 +151,34 @@ func TestCheckoutGit(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- cases := []struct {
|
|
|
+ type singleCase struct {
|
|
|
frag string
|
|
|
exp string
|
|
|
fail bool
|
|
|
- }{
|
|
|
+ }
|
|
|
+
|
|
|
+ cases := []singleCase{
|
|
|
{"", "FROM scratch", false},
|
|
|
{"master", "FROM scratch", false},
|
|
|
- {":subdir", "FROM scratch\nEXPOSE 5000", false},
|
|
|
+ {":subdir", "FROM scratch" + eol + "EXPOSE 5000", false},
|
|
|
{":nosubdir", "", true}, // missing directory error
|
|
|
{":Dockerfile", "", true}, // not a directory error
|
|
|
{"master:nosubdir", "", true},
|
|
|
- {"master:subdir", "FROM scratch\nEXPOSE 5000", false},
|
|
|
- {"master:parentlink", "FROM scratch\nEXPOSE 5000", false},
|
|
|
- {"master:absolutelink", "FROM scratch\nEXPOSE 5000", false},
|
|
|
+ {"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false},
|
|
|
{"master:../subdir", "", true},
|
|
|
- {"test", "FROM scratch\nEXPOSE 3000", false},
|
|
|
- {"test:", "FROM scratch\nEXPOSE 3000", false},
|
|
|
- {"test:subdir", "FROM busybox\nEXPOSE 5000", false},
|
|
|
+ {"test", "FROM scratch" + eol + "EXPOSE 3000", false},
|
|
|
+ {"test:", "FROM scratch" + eol + "EXPOSE 3000", false},
|
|
|
+ {"test:subdir", "FROM busybox" + eol + "EXPOSE 5000", false},
|
|
|
+ }
|
|
|
+
|
|
|
+ if runtime.GOOS != "windows" {
|
|
|
+ // Windows GIT (2.7.1 x64) does not support parentlink/absolutelink. Sample output below
|
|
|
+ // git --work-tree .\repo --git-dir .\repo\.git add -A
|
|
|
+ // error: readlink("absolutelink"): Function not implemented
|
|
|
+ // error: unable to index file absolutelink
|
|
|
+ // fatal: adding files failed
|
|
|
+ cases = append(cases, singleCase{frag: "master:absolutelink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
|
|
+ cases = append(cases, singleCase{frag: "master:parentlink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
|
|
}
|
|
|
|
|
|
for _, c := range cases {
|