9 check "gopkg.in/check.v1"
12 var _ = check.Suite(&GitoliteSuite{})
14 // GitoliteSuite tests need an API server, an arv-git-httpd server,
15 // and a repository hosted by gitolite.
16 type GitoliteSuite struct {
21 func (s *GitoliteSuite) SetUpTest(c *check.C) {
23 s.gitoliteHome, err = ioutil.TempDir("", "arv-git-httpd")
24 c.Assert(err, check.Equals, nil)
26 runGitolite := func(prog string, args ...string) {
27 c.Log(prog, " ", args)
28 cmd := exec.Command(prog, args...)
29 cmd.Dir = s.gitoliteHome
30 cmd.Env = []string{"HOME=" + s.gitoliteHome}
31 for _, e := range os.Environ() {
32 if !strings.HasPrefix(e, "HOME=") {
33 cmd.Env = append(cmd.Env, e)
36 diags, err := cmd.CombinedOutput()
38 c.Assert(err, check.Equals, nil)
41 runGitolite("gitolite", "setup", "--admin", "root")
43 s.tmpRepoRoot = s.gitoliteHome + "/repositories"
46 GitCommand: "/usr/share/gitolite3/gitolite-shell",
49 s.IntegrationSuite.SetUpTest(c)
51 // Install the gitolite hooks in the bare repo we made in
52 // (*IntegrationTest)SetUpTest() -- see 2.2.4 at
53 // http://gitolite.com/gitolite/gitolite.html
54 runGitolite("gitolite", "setup")
56 os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
57 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
60 func (s *GitoliteSuite) TearDownTest(c *check.C) {
61 // We really want Unsetenv here, but it's not worth forcing an
63 os.Setenv("GITOLITE_HTTP_HOME", "")
64 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
65 s.IntegrationSuite.TearDownTest(c)
68 func (s *GitoliteSuite) TestFetch(c *check.C) {
69 err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
70 c.Check(err, check.Equals, nil)
73 func (s *GitoliteSuite) TestFetchUnreadable(c *check.C) {
74 err := s.RunGit(c, anonymousToken, "fetch", "active/foo.git")
75 c.Check(err, check.ErrorMatches, `.* not found.*`)
78 func (s *GitoliteSuite) TestPush(c *check.C) {
79 err := s.RunGit(c, activeToken, "push", "active/foo.git", "master:gitolite-push")
80 c.Check(err, check.Equals, nil)
82 // Check that the commit hash appears in the gitolite log, as
83 // assurance that the gitolite hooks really did run.
85 sha1, err := exec.Command("git", "--git-dir", s.tmpWorkdir+"/.git",
86 "log", "-n1", "--format=%H").CombinedOutput()
87 c.Logf("git-log in workdir: %q", string(sha1))
88 c.Assert(err, check.Equals, nil)
89 c.Assert(len(sha1), check.Equals, 41)
91 gitoliteLog, err := exec.Command("grep", "-r", string(sha1[:40]), s.gitoliteHome+"/.gitolite/logs").CombinedOutput()
92 c.Check(err, check.Equals, nil)
93 c.Logf("gitolite log message: %q", string(gitoliteLog))
96 func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
97 err := s.RunGit(c, spectatorToken, "push", "active/foo.git", "master:gitolite-push-fail")
98 c.Check(err, check.ErrorMatches, `.*HTTP code = 403.*`)