11 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
12 check "gopkg.in/check.v1"
15 // Gocheck boilerplate
16 func Test(t *testing.T) {
20 // IntegrationSuite tests need an API server and an arv-git-httpd
21 // server. See GitSuite and GitoliteSuite.
22 type IntegrationSuite struct {
29 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
30 arvadostest.StartAPI()
33 func (s *IntegrationSuite) TearDownSuite(c *check.C) {
37 func (s *IntegrationSuite) SetUpTest(c *check.C) {
38 arvadostest.ResetEnv()
39 s.testServer = &server{}
41 if s.tmpRepoRoot == "" {
42 s.tmpRepoRoot, err = ioutil.TempDir("", "arv-git-httpd")
43 c.Assert(err, check.Equals, nil)
45 s.tmpWorkdir, err = ioutil.TempDir("", "arv-git-httpd")
46 c.Assert(err, check.Equals, nil)
47 _, err = exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git").Output()
48 c.Assert(err, check.Equals, nil)
49 _, err = exec.Command("git", "init", s.tmpWorkdir).Output()
50 c.Assert(err, check.Equals, nil)
51 _, 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()
52 c.Assert(err, check.Equals, nil)
53 _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && git push "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git master:master").CombinedOutput()
54 c.Assert(err, check.Equals, nil)
55 _, 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()
56 c.Assert(err, check.Equals, nil)
58 _, err = exec.Command("git", "config",
59 "--file", s.tmpWorkdir+"/.git/config",
60 "credential.http://"+s.testServer.Addr+"/.helper",
61 "!cred(){ cat >/dev/null; if [ \"$1\" = get ]; then echo password=$ARVADOS_API_TOKEN; fi; };cred").Output()
62 c.Assert(err, check.Equals, nil)
63 _, err = exec.Command("git", "config",
64 "--file", s.tmpWorkdir+"/.git/config",
65 "credential.http://"+s.testServer.Addr+"/.username",
67 c.Assert(err, check.Equals, nil)
72 GitCommand: "/usr/bin/git",
77 err = s.testServer.Start()
78 c.Assert(err, check.Equals, nil)
80 // Clear ARVADOS_API_TOKEN after starting up the server, to
81 // make sure arv-git-httpd doesn't use it.
82 os.Setenv("ARVADOS_API_TOKEN", "unused-token-placates-client-library")
85 func (s *IntegrationSuite) TearDownTest(c *check.C) {
87 if s.testServer != nil {
88 err = s.testServer.Close()
90 c.Check(err, check.Equals, nil)
93 if s.tmpRepoRoot != "" {
94 err = os.RemoveAll(s.tmpRepoRoot)
95 c.Check(err, check.Equals, nil)
99 if s.tmpWorkdir != "" {
100 err = os.RemoveAll(s.tmpWorkdir)
101 c.Check(err, check.Equals, nil)
108 func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error {
109 cwd, err := os.Getwd()
110 c.Assert(err, check.Equals, nil)
112 os.Chdir(s.tmpWorkdir)
114 gitargs := append([]string{
115 gitCmd, "http://" + s.testServer.Addr + "/" + repo,
117 cmd := exec.Command("git", gitargs...)
118 cmd.Env = append(os.Environ(), "ARVADOS_API_TOKEN="+token)
119 w, err := cmd.StdinPipe()
120 c.Assert(err, check.Equals, nil)
122 output, err := cmd.CombinedOutput()
123 c.Log("git ", gitargs, " => ", err)
124 c.Log(string(output))
125 if err != nil && len(output) > 0 {
126 // If messages appeared on stderr, they are more
127 // helpful than the err returned by CombinedOutput().
129 // Easier to match error strings without newlines:
130 err = errors.New(strings.Replace(string(output), "\n", " // ", -1))