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 GitoliteHome: s.gitoliteHome,
54 RepoRoot: s.tmpRepoRoot,
56 s.IntegrationSuite.SetUpTest(c)
58 // Install the gitolite hooks in the bare repo we made in
59 // (*IntegrationTest)SetUpTest() -- see 2.2.4 at
60 // http://gitolite.com/gitolite/gitolite.html
61 runGitolite("gitolite", "setup")
64 func (s *GitoliteSuite) TearDownTest(c *check.C) {
65 // We really want Unsetenv here, but it's not worth forcing an
67 os.Setenv("GITOLITE_HTTP_HOME", "")
68 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
69 if s.gitoliteHome != "" {
70 err := os.RemoveAll(s.gitoliteHome)
71 c.Check(err, check.Equals, nil)
73 s.IntegrationSuite.TearDownTest(c)
76 func (s *GitoliteSuite) TestFetch(c *check.C) {
77 err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
78 c.Check(err, check.Equals, nil)
81 func (s *GitoliteSuite) TestFetchUnreadable(c *check.C) {
82 err := s.RunGit(c, anonymousToken, "fetch", "active/foo.git")
83 c.Check(err, check.ErrorMatches, `.* not found.*`)
86 func (s *GitoliteSuite) TestPush(c *check.C) {
87 err := s.RunGit(c, activeToken, "push", "active/foo.git", "master:gitolite-push")
88 c.Check(err, check.Equals, nil)
90 // Check that the commit hash appears in the gitolite log, as
91 // assurance that the gitolite hooks really did run.
93 sha1, err := exec.Command("git", "--git-dir", s.tmpWorkdir+"/.git",
94 "log", "-n1", "--format=%H").CombinedOutput()
95 c.Logf("git-log in workdir: %q", string(sha1))
96 c.Assert(err, check.Equals, nil)
97 c.Assert(len(sha1), check.Equals, 41)
99 gitoliteLog, err := exec.Command("grep", "-r", string(sha1[:40]), s.gitoliteHome+"/.gitolite/logs").CombinedOutput()
100 c.Check(err, check.Equals, nil)
101 c.Logf("gitolite log message: %q", string(gitoliteLog))
104 func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
105 err := s.RunGit(c, spectatorToken, "push", "active/foo.git", "master:gitolite-push-fail")
106 c.Check(err, check.ErrorMatches, `.*HTTP code = 403.*`)