[ARVADOS] created: b4151bcf5010bf6c8f26c819eb569cd58442cd1c
git at public.curoverse.com
git at public.curoverse.com
Wed Sep 2 03:06:20 EDT 2015
at b4151bcf5010bf6c8f26c819eb569cd58442cd1c (commit)
commit b4151bcf5010bf6c8f26c819eb569cd58442cd1c
Author: Tom Clegg <tom at curoverse.com>
Date: Wed Sep 2 03:06:05 2015 -0400
6263: Add gitolite integration test. Fix existing tests to use bare repos on server side.
diff --git a/services/arv-git-httpd/gitolite_test.go b/services/arv-git-httpd/gitolite_test.go
new file mode 100644
index 0000000..9596ecd
--- /dev/null
+++ b/services/arv-git-httpd/gitolite_test.go
@@ -0,0 +1,89 @@
+package main
+
+import (
+ "os"
+ "os/exec"
+ "io/ioutil"
+
+ check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&GitoliteSuite{})
+
+// GitoliteSuite tests need an API server, an arv-git-httpd server,
+// and a repository hosted by gitolite.
+type GitoliteSuite struct {
+ serverSuite IntegrationSuite
+ gitoliteHome string
+}
+
+func (s *GitoliteSuite) SetUpTest(c *check.C) {
+ var err error
+ s.gitoliteHome, err = ioutil.TempDir("", "arv-git-httpd")
+ c.Assert(err, check.Equals, nil)
+
+ runGitolite := func(prog string, args ...string) {
+ c.Log(prog, " ", args)
+ cmd := exec.Command(prog, args...)
+ cmd.Dir = s.gitoliteHome
+ cmd.Env = append(os.Environ(), "HOME=" + s.gitoliteHome)
+ diags, err := cmd.CombinedOutput()
+ c.Log(string(diags))
+ c.Assert(err, check.Equals, nil)
+ }
+
+ runGitolite("gitolite", "setup", "--admin", "root")
+
+ s.serverSuite.tmpRepoRoot = s.gitoliteHome + "/repositories"
+ s.serverSuite.Config = &config{
+ Addr: ":0",
+ GitCommand: "/usr/share/gitolite3/gitolite-shell",
+ Root: s.serverSuite.tmpRepoRoot,
+ }
+ s.serverSuite.SetUpTest(c)
+
+ // Install the gitolite hooks in the bare repo we made in
+ // s.serverSuite.SetUpTest() -- see 2.2.4 at
+ // http://gitolite.com/gitolite/gitolite.html
+ runGitolite("gitolite", "setup")
+
+ os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
+ os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
+}
+
+func (s *GitoliteSuite) TearDownTest(c *check.C) {
+ s.serverSuite.TearDownTest(c)
+}
+
+func (s *GitoliteSuite) TestFetch(c *check.C) {
+ err := s.serverSuite.runGit(c, activeToken, "fetch", "active/foo.git")
+ c.Check(err, check.Equals, nil)
+}
+
+func (s *GitoliteSuite) TestFetchUnreadable(c *check.C) {
+ err := s.serverSuite.runGit(c, anonymousToken, "fetch", "active/foo.git")
+ c.Check(err, check.ErrorMatches, `.* not found.*`)
+}
+
+func (s *GitoliteSuite) TestPush(c *check.C) {
+ err := s.serverSuite.runGit(c, activeToken, "push", "active/foo.git")
+ c.Check(err, check.Equals, nil)
+
+ // Check that the commit hash appears in the gitolite log, as
+ // assurance that the gitolite hooks really did run.
+
+ sha1, err := exec.Command("git", "--git-dir", s.serverSuite.tmpWorkdir + "/.git",
+ "log", "-n1", "--format=%H").CombinedOutput()
+ c.Logf("git-log in workdir: %q", string(sha1))
+ c.Assert(err, check.Equals, nil)
+ c.Assert(len(sha1), check.Equals, 41)
+
+ gitoliteLog, err := exec.Command("grep", "-r", string(sha1[:40]), s.gitoliteHome + "/.gitolite/logs").CombinedOutput()
+ c.Check(err, check.Equals, nil)
+ c.Logf("gitolite log message: %q", string(gitoliteLog))
+}
+
+func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
+ err := s.serverSuite.runGit(c, spectatorToken, "push", "active/foo.git")
+ c.Check(err, check.ErrorMatches, `.*HTTP code = 403.*`)
+}
diff --git a/services/arv-git-httpd/server_test.go b/services/arv-git-httpd/server_test.go
index c1364ca..7709dcc 100644
--- a/services/arv-git-httpd/server_test.go
+++ b/services/arv-git-httpd/server_test.go
@@ -26,6 +26,7 @@ type IntegrationSuite struct {
tmpRepoRoot string
tmpWorkdir string
testServer *server
+ Config *config
}
func (s *IntegrationSuite) TestPathVariants(c *check.C) {
@@ -41,7 +42,7 @@ func (s *IntegrationSuite) TestReadonly(c *check.C) {
c.Assert(err, check.Equals, nil)
err = s.runGit(c, spectatorToken, "push", "active/foo.git", "master:newbranchfail")
c.Assert(err, check.ErrorMatches, `.*HTTP code = 403.*`)
- _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666/.git/refs/heads/newbranchfail")
+ _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranchfail")
c.Assert(err, check.FitsTypeOf, &os.PathError{})
}
@@ -50,7 +51,7 @@ func (s *IntegrationSuite) TestReadwrite(c *check.C) {
c.Assert(err, check.Equals, nil)
err = s.runGit(c, activeToken, "push", "active/foo.git", "master:newbranch")
c.Assert(err, check.Equals, nil)
- _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666/.git/refs/heads/newbranch")
+ _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranch")
c.Assert(err, check.Equals, nil)
}
@@ -111,16 +112,20 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
arvadostest.ResetEnv()
s.testServer = &server{}
var err error
- s.tmpRepoRoot, err = ioutil.TempDir("", "arv-git-httpd")
- c.Assert(err, check.Equals, nil)
+ if s.tmpRepoRoot == "" {
+ s.tmpRepoRoot, err = ioutil.TempDir("", "arv-git-httpd")
+ c.Assert(err, check.Equals, nil)
+ }
s.tmpWorkdir, err = ioutil.TempDir("", "arv-git-httpd")
c.Assert(err, check.Equals, nil)
- _, err = exec.Command("git", "init", s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666").Output()
- c.Assert(err, check.Equals, nil)
- _, err = exec.Command("sh", "-c", "cd "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666 && echo test >test && git add test && git -c user.name=Foo -c user.email=Foo commit -am 'foo: test'").CombinedOutput()
+ _, err = exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git").Output()
c.Assert(err, check.Equals, nil)
_, err = exec.Command("git", "init", s.tmpWorkdir).Output()
c.Assert(err, check.Equals, nil)
+ _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && echo initial >initial && git add initial && git -c user.name=Initial -c user.email=Initial commit -am 'foo: initial commit'").CombinedOutput()
+ c.Assert(err, check.Equals, nil)
+ _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && git push "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git master:master").CombinedOutput()
+ c.Assert(err, check.Equals, nil)
_, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && echo work >work && git add work && git -c user.name=Foo -c user.email=Foo commit -am 'workdir: test'").CombinedOutput()
c.Assert(err, check.Equals, nil)
@@ -135,11 +140,14 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
"none").Output()
c.Assert(err, check.Equals, nil)
- theConfig = &config{
- Addr: ":0",
- GitCommand: "/usr/bin/git",
- Root: s.tmpRepoRoot,
+ if s.Config == nil {
+ s.Config = &config{
+ Addr: ":0",
+ GitCommand: "/usr/bin/git",
+ Root: s.tmpRepoRoot,
+ }
}
+ theConfig = s.Config
err = s.testServer.Start()
c.Assert(err, check.Equals, nil)
@@ -154,14 +162,21 @@ func (s *IntegrationSuite) TearDownTest(c *check.C) {
err = s.testServer.Close()
}
c.Check(err, check.Equals, nil)
+ s.testServer = nil
+
if s.tmpRepoRoot != "" {
err = os.RemoveAll(s.tmpRepoRoot)
c.Check(err, check.Equals, nil)
}
+ s.tmpRepoRoot = ""
+
if s.tmpWorkdir != "" {
err = os.RemoveAll(s.tmpWorkdir)
c.Check(err, check.Equals, nil)
}
+ s.tmpWorkdir = ""
+
+ s.Config = nil
}
func (s *IntegrationSuite) runGit(c *check.C, token, gitCmd, repo string, args ...string) error {
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list