1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Windows CI: Unit tests - port pkg\gitutils

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-02-11 18:19:17 -08:00
parent 5ca6d3bafd
commit eaf41b7410

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,6 +109,7 @@ func TestCheckoutGit(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if runtime.GOOS != "windows" {
if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil { if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -110,6 +117,7 @@ func TestCheckoutGit(t *testing.T) {
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 {
t.Fatal(err) t.Fatal(err)
@ -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 {