9 "git.curoverse.com/arvados.git/sdk/go/arvados"
10 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
11 check "gopkg.in/check.v1"
14 var _ = check.Suite(&GitoliteSuite{})
16 // GitoliteSuite tests need an API server, an arv-git-httpd server,
17 // and a repository hosted by gitolite.
18 type GitoliteSuite struct {
23 func (s *GitoliteSuite) SetUpTest(c *check.C) {
25 s.gitoliteHome, err = ioutil.TempDir("", "arv-git-httpd")
26 c.Assert(err, check.Equals, nil)
28 runGitolite := func(prog string, args ...string) {
29 c.Log(prog, " ", args)
30 cmd := exec.Command(prog, args...)
31 cmd.Dir = s.gitoliteHome
32 cmd.Env = []string{"HOME=" + s.gitoliteHome}
33 for _, e := range os.Environ() {
34 if !strings.HasPrefix(e, "HOME=") {
35 cmd.Env = append(cmd.Env, e)
38 diags, err := cmd.CombinedOutput()
40 c.Assert(err, check.Equals, nil)
43 runGitolite("gitolite", "setup", "--admin", "root")
45 s.tmpRepoRoot = s.gitoliteHome + "/repositories"
47 Client: arvados.Client{
48 APIHost: arvadostest.APIHost(),
52 GitCommand: "/usr/share/gitolite3/gitolite-shell",
53 RepoRoot: s.tmpRepoRoot,
55 s.IntegrationSuite.SetUpTest(c)
57 // Install the gitolite hooks in the bare repo we made in
58 // (*IntegrationTest)SetUpTest() -- see 2.2.4 at
59 // http://gitolite.com/gitolite/gitolite.html
60 runGitolite("gitolite", "setup")
62 os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
63 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
66 func (s *GitoliteSuite) TearDownTest(c *check.C) {
67 // We really want Unsetenv here, but it's not worth forcing an
69 os.Setenv("GITOLITE_HTTP_HOME", "")
70 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
71 if s.gitoliteHome != "" {
72 err := os.RemoveAll(s.gitoliteHome)
73 c.Check(err, check.Equals, nil)
75 s.IntegrationSuite.TearDownTest(c)
78 func (s *GitoliteSuite) TestFetch(c *check.C) {
79 err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
80 c.Check(err, check.Equals, nil)
83 func (s *GitoliteSuite) TestFetchUnreadable(c *check.C) {
84 err := s.RunGit(c, anonymousToken, "fetch", "active/foo.git")
85 c.Check(err, check.ErrorMatches, `.* not found.*`)
88 func (s *GitoliteSuite) TestPush(c *check.C) {
89 err := s.RunGit(c, activeToken, "push", "active/foo.git", "master:gitolite-push")
90 c.Check(err, check.Equals, nil)
92 // Check that the commit hash appears in the gitolite log, as
93 // assurance that the gitolite hooks really did run.
95 sha1, err := exec.Command("git", "--git-dir", s.tmpWorkdir+"/.git",
96 "log", "-n1", "--format=%H").CombinedOutput()
97 c.Logf("git-log in workdir: %q", string(sha1))
98 c.Assert(err, check.Equals, nil)
99 c.Assert(len(sha1), check.Equals, 41)
101 gitoliteLog, err := exec.Command("grep", "-r", string(sha1[:40]), s.gitoliteHome+"/.gitolite/logs").CombinedOutput()
102 c.Check(err, check.Equals, nil)
103 c.Logf("gitolite log message: %q", string(gitoliteLog))
106 func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
107 err := s.RunGit(c, spectatorToken, "push", "active/foo.git", "master:gitolite-push-fail")
108 c.Check(err, check.ErrorMatches, `.*HTTP code = 403.*`)