11 "git.curoverse.com/arvados.git/sdk/go/arvados"
12 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
13 check "gopkg.in/check.v1"
16 // Gocheck boilerplate
17 func Test(t *testing.T) {
21 // IntegrationSuite tests need an API server and an arv-git-httpd
22 // server. See GitSuite and GitoliteSuite.
23 type IntegrationSuite struct {
30 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
31 arvadostest.StartAPI()
34 func (s *IntegrationSuite) TearDownSuite(c *check.C) {
38 func (s *IntegrationSuite) SetUpTest(c *check.C) {
39 arvadostest.ResetEnv()
40 s.testServer = &server{}
42 if s.tmpRepoRoot == "" {
43 s.tmpRepoRoot, err = ioutil.TempDir("", "arv-git-httpd")
44 c.Assert(err, check.Equals, nil)
46 s.tmpWorkdir, err = ioutil.TempDir("", "arv-git-httpd")
47 c.Assert(err, check.Equals, nil)
48 _, err = exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git").Output()
49 c.Assert(err, check.Equals, nil)
50 _, err = exec.Command("git", "init", s.tmpWorkdir).Output()
51 c.Assert(err, check.Equals, nil)
52 _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && echo initial >initial && git add initial && git -c user.name=Initial -c user.email=Initial commit -am 'foo: initial commit'").CombinedOutput()
53 c.Assert(err, check.Equals, nil)
54 _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && git push "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git master:master").CombinedOutput()
55 c.Assert(err, check.Equals, nil)
56 _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && echo work >work && git add work && git -c user.name=Foo -c user.email=Foo commit -am 'workdir: test'").CombinedOutput()
57 c.Assert(err, check.Equals, nil)
59 _, err = exec.Command("git", "config",
60 "--file", s.tmpWorkdir+"/.git/config",
61 "credential.http://"+s.testServer.Addr+"/.helper",
62 "!cred(){ cat >/dev/null; if [ \"$1\" = get ]; then echo password=$ARVADOS_API_TOKEN; fi; };cred").Output()
63 c.Assert(err, check.Equals, nil)
64 _, err = exec.Command("git", "config",
65 "--file", s.tmpWorkdir+"/.git/config",
66 "credential.http://"+s.testServer.Addr+"/.username",
68 c.Assert(err, check.Equals, nil)
72 Client: arvados.Client{
73 APIHost: arvadostest.APIHost(),
77 GitCommand: "/usr/bin/git",
78 RepoRoot: s.tmpRepoRoot,
82 // Clear ARVADOS_API_* env vars before starting up the server,
83 // to make sure arv-git-httpd doesn't use them or complain
84 // about them being missing.
85 os.Unsetenv("ARVADOS_API_HOST")
86 os.Unsetenv("ARVADOS_API_HOST_INSECURE")
87 os.Unsetenv("ARVADOS_API_TOKEN")
90 err = s.testServer.Start()
91 c.Assert(err, check.Equals, nil)
94 func (s *IntegrationSuite) TearDownTest(c *check.C) {
96 if s.testServer != nil {
97 err = s.testServer.Close()
99 c.Check(err, check.Equals, nil)
102 if s.tmpRepoRoot != "" {
103 err = os.RemoveAll(s.tmpRepoRoot)
104 c.Check(err, check.Equals, nil)
108 if s.tmpWorkdir != "" {
109 err = os.RemoveAll(s.tmpWorkdir)
110 c.Check(err, check.Equals, nil)
117 func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error {
118 cwd, err := os.Getwd()
119 c.Assert(err, check.Equals, nil)
121 os.Chdir(s.tmpWorkdir)
123 gitargs := append([]string{
124 gitCmd, "http://" + s.testServer.Addr + "/" + repo,
126 cmd := exec.Command("git", gitargs...)
127 cmd.Env = append(os.Environ(), "ARVADOS_API_TOKEN="+token)
128 w, err := cmd.StdinPipe()
129 c.Assert(err, check.Equals, nil)
131 output, err := cmd.CombinedOutput()
132 c.Log("git ", gitargs, " => ", err)
133 c.Log(string(output))
134 if err != nil && len(output) > 0 {
135 // If messages appeared on stderr, they are more
136 // helpful than the err returned by CombinedOutput().
138 // Easier to match error strings without newlines:
139 err = errors.New(strings.Replace(string(output), "\n", " // ", -1))