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