Merge pull request #20260 from Microsoft/jjh/testunit-pkggitutils

Windows CI: Unit tests - port pkg\gitutils
This commit is contained in:
David Calavera 2016-02-17 13:50:17 -08:00
commit 7100db90d0

View file

@ -9,6 +9,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime"
"testing" "testing"
) )
@ -76,6 +77,11 @@ func TestCheckoutGit(t *testing.T) {
} }
defer os.RemoveAll(root) defer os.RemoveAll(root)
eol := "\n"
if runtime.GOOS == "windows" {
eol = "\r\n"
}
gitDir := filepath.Join(root, "repo") gitDir := filepath.Join(root, "repo")
_, err = git("init", gitDir) _, err = git("init", gitDir)
if err != nil { if err != nil {
@ -103,12 +109,14 @@ func TestCheckoutGit(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil { if runtime.GOOS != "windows" {
t.Fatal(err) 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 { if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
t.Fatal(err) t.Fatal(err)
}
} }
if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil { if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil {
@ -143,24 +151,34 @@ func TestCheckoutGit(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
cases := []struct { type singleCase struct {
frag string frag string
exp string exp string
fail bool fail bool
}{ }
cases := []singleCase{
{"", "FROM scratch", false}, {"", "FROM scratch", false},
{"master", "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 {":nosubdir", "", true}, // missing directory error
{":Dockerfile", "", true}, // not a directory error {":Dockerfile", "", true}, // not a directory error
{"master:nosubdir", "", true}, {"master:nosubdir", "", true},
{"master:subdir", "FROM scratch\nEXPOSE 5000", false}, {"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false},
{"master:parentlink", "FROM scratch\nEXPOSE 5000", false},
{"master:absolutelink", "FROM scratch\nEXPOSE 5000", false},
{"master:../subdir", "", true}, {"master:../subdir", "", true},
{"test", "FROM scratch\nEXPOSE 3000", false}, {"test", "FROM scratch" + eol + "EXPOSE 3000", false},
{"test:", "FROM scratch\nEXPOSE 3000", false}, {"test:", "FROM scratch" + eol + "EXPOSE 3000", false},
{"test:subdir", "FROM busybox\nEXPOSE 5000", 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 { for _, c := range cases {