8 check "gopkg.in/check.v1"
11 var _ = check.Suite(&GitoliteSuite{})
13 // GitoliteSuite tests need an API server, an arv-git-httpd server,
14 // and a repository hosted by gitolite.
15 type GitoliteSuite struct {
20 func (s *GitoliteSuite) SetUpTest(c *check.C) {
22 s.gitoliteHome, err = ioutil.TempDir("", "arv-git-httpd")
23 c.Assert(err, check.Equals, nil)
25 runGitolite := func(prog string, args ...string) {
26 c.Log(prog, " ", args)
27 cmd := exec.Command(prog, args...)
28 cmd.Dir = s.gitoliteHome
29 cmd.Env = append(os.Environ(), "HOME=" + s.gitoliteHome)
30 diags, err := cmd.CombinedOutput()
32 c.Assert(err, check.Equals, nil)
35 runGitolite("gitolite", "setup", "--admin", "root")
37 s.tmpRepoRoot = s.gitoliteHome + "/repositories"
40 GitCommand: "/usr/share/gitolite3/gitolite-shell",
43 s.IntegrationSuite.SetUpTest(c)
45 // Install the gitolite hooks in the bare repo we made in
46 // (*IntegrationTest)SetUpTest() -- see 2.2.4 at
47 // http://gitolite.com/gitolite/gitolite.html
48 runGitolite("gitolite", "setup")
50 os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
51 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
54 func (s *GitoliteSuite) TearDownTest(c *check.C) {
55 // We really want Unsetenv here, but it's not worth forcing an
57 os.Setenv("GITOLITE_HTTP_HOME", "")
58 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
59 s.IntegrationSuite.TearDownTest(c)
62 func (s *GitoliteSuite) TestFetch(c *check.C) {
63 err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
64 c.Check(err, check.Equals, nil)
67 func (s *GitoliteSuite) TestFetchUnreadable(c *check.C) {
68 err := s.RunGit(c, anonymousToken, "fetch", "active/foo.git")
69 c.Check(err, check.ErrorMatches, `.* not found.*`)
72 func (s *GitoliteSuite) TestPush(c *check.C) {
73 err := s.RunGit(c, activeToken, "push", "active/foo.git")
74 c.Check(err, check.Equals, nil)
76 // Check that the commit hash appears in the gitolite log, as
77 // assurance that the gitolite hooks really did run.
79 sha1, err := exec.Command("git", "--git-dir", s.tmpWorkdir + "/.git",
80 "log", "-n1", "--format=%H").CombinedOutput()
81 c.Logf("git-log in workdir: %q", string(sha1))
82 c.Assert(err, check.Equals, nil)
83 c.Assert(len(sha1), check.Equals, 41)
85 gitoliteLog, err := exec.Command("grep", "-r", string(sha1[:40]), s.gitoliteHome + "/.gitolite/logs").CombinedOutput()
86 c.Check(err, check.Equals, nil)
87 c.Logf("gitolite log message: %q", string(gitoliteLog))
90 func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
91 err := s.RunGit(c, spectatorToken, "push", "active/foo.git")
92 c.Check(err, check.ErrorMatches, `.*HTTP code = 403.*`)