Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"os" |
| 10 | 10 |
"path/filepath" |
| 11 | 11 |
"reflect" |
| 12 |
+ "runtime" |
|
| 12 | 13 |
"testing" |
| 13 | 14 |
) |
| 14 | 15 |
|
| ... | ... |
@@ -76,6 +77,11 @@ func TestCheckoutGit(t *testing.T) {
|
| 76 | 76 |
} |
| 77 | 77 |
defer os.RemoveAll(root) |
| 78 | 78 |
|
| 79 |
+ eol := "\n" |
|
| 80 |
+ if runtime.GOOS == "windows" {
|
|
| 81 |
+ eol = "\r\n" |
|
| 82 |
+ } |
|
| 83 |
+ |
|
| 79 | 84 |
gitDir := filepath.Join(root, "repo") |
| 80 | 85 |
_, err = git("init", gitDir)
|
| 81 | 86 |
if err != nil {
|
| ... | ... |
@@ -103,12 +109,14 @@ func TestCheckoutGit(t *testing.T) {
|
| 103 | 103 |
t.Fatal(err) |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
- if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
|
|
| 107 |
- t.Fatal(err) |
|
| 108 |
- } |
|
| 106 |
+ if runtime.GOOS != "windows" {
|
|
| 107 |
+ if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
|
|
| 108 |
+ t.Fatal(err) |
|
| 109 |
+ } |
|
| 109 | 110 |
|
| 110 |
- if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
|
|
| 111 |
- t.Fatal(err) |
|
| 111 |
+ if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
|
|
| 112 |
+ t.Fatal(err) |
|
| 113 |
+ } |
|
| 112 | 114 |
} |
| 113 | 115 |
|
| 114 | 116 |
if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil {
|
| ... | ... |
@@ -143,24 +151,34 @@ func TestCheckoutGit(t *testing.T) {
|
| 143 | 143 |
t.Fatal(err) |
| 144 | 144 |
} |
| 145 | 145 |
|
| 146 |
- cases := []struct {
|
|
| 146 |
+ type singleCase struct {
|
|
| 147 | 147 |
frag string |
| 148 | 148 |
exp string |
| 149 | 149 |
fail bool |
| 150 |
- }{
|
|
| 150 |
+ } |
|
| 151 |
+ |
|
| 152 |
+ cases := []singleCase{
|
|
| 151 | 153 |
{"", "FROM scratch", false},
|
| 152 | 154 |
{"master", "FROM scratch", false},
|
| 153 |
- {":subdir", "FROM scratch\nEXPOSE 5000", false},
|
|
| 155 |
+ {":subdir", "FROM scratch" + eol + "EXPOSE 5000", false},
|
|
| 154 | 156 |
{":nosubdir", "", true}, // missing directory error
|
| 155 | 157 |
{":Dockerfile", "", true}, // not a directory error
|
| 156 | 158 |
{"master:nosubdir", "", true},
|
| 157 |
- {"master:subdir", "FROM scratch\nEXPOSE 5000", false},
|
|
| 158 |
- {"master:parentlink", "FROM scratch\nEXPOSE 5000", false},
|
|
| 159 |
- {"master:absolutelink", "FROM scratch\nEXPOSE 5000", false},
|
|
| 159 |
+ {"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false},
|
|
| 160 | 160 |
{"master:../subdir", "", true},
|
| 161 |
- {"test", "FROM scratch\nEXPOSE 3000", false},
|
|
| 162 |
- {"test:", "FROM scratch\nEXPOSE 3000", false},
|
|
| 163 |
- {"test:subdir", "FROM busybox\nEXPOSE 5000", false},
|
|
| 161 |
+ {"test", "FROM scratch" + eol + "EXPOSE 3000", false},
|
|
| 162 |
+ {"test:", "FROM scratch" + eol + "EXPOSE 3000", false},
|
|
| 163 |
+ {"test:subdir", "FROM busybox" + eol + "EXPOSE 5000", false},
|
|
| 164 |
+ } |
|
| 165 |
+ |
|
| 166 |
+ if runtime.GOOS != "windows" {
|
|
| 167 |
+ // Windows GIT (2.7.1 x64) does not support parentlink/absolutelink. Sample output below |
|
| 168 |
+ // git --work-tree .\repo --git-dir .\repo\.git add -A |
|
| 169 |
+ // error: readlink("absolutelink"): Function not implemented
|
|
| 170 |
+ // error: unable to index file absolutelink |
|
| 171 |
+ // fatal: adding files failed |
|
| 172 |
+ cases = append(cases, singleCase{frag: "master:absolutelink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
|
| 173 |
+ cases = append(cases, singleCase{frag: "master:parentlink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
|
| 164 | 174 |
} |
| 165 | 175 |
|
| 166 | 176 |
for _, c := range cases {
|