[ARVADOS] updated: 7bf0bc0355fde5829644df8557990cd2353d92b6

git at public.curoverse.com git at public.curoverse.com
Wed Sep 2 10:17:19 EDT 2015


Summary of changes:
 services/arv-git-httpd/gitolite_test.go            |  28 ++--
 .../{server_test.go => integration_test.go}        | 103 +-----------
 services/arv-git-httpd/server_test.go              | 172 ++++-----------------
 3 files changed, 49 insertions(+), 254 deletions(-)
 copy services/arv-git-httpd/{server_test.go => integration_test.go} (51%)

       via  7bf0bc0355fde5829644df8557990cd2353d92b6 (commit)
      from  b4151bcf5010bf6c8f26c819eb569cd58442cd1c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 7bf0bc0355fde5829644df8557990cd2353d92b6
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Sep 2 10:17:09 2015 -0400

    6263: Rearrange test suites to share code better.

diff --git a/services/arv-git-httpd/gitolite_test.go b/services/arv-git-httpd/gitolite_test.go
index 9596ecd..8458730 100644
--- a/services/arv-git-httpd/gitolite_test.go
+++ b/services/arv-git-httpd/gitolite_test.go
@@ -13,7 +13,7 @@ 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
+	IntegrationSuite
 	gitoliteHome string
 }
 
@@ -34,16 +34,16 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
 
 	runGitolite("gitolite", "setup", "--admin", "root")
 
-	s.serverSuite.tmpRepoRoot = s.gitoliteHome + "/repositories"
-	s.serverSuite.Config = &config{
+	s.tmpRepoRoot = s.gitoliteHome + "/repositories"
+	s.Config = &config{
 		Addr:       ":0",
 		GitCommand: "/usr/share/gitolite3/gitolite-shell",
-		Root:       s.serverSuite.tmpRepoRoot,
+		Root:       s.tmpRepoRoot,
 	}
-	s.serverSuite.SetUpTest(c)
+	s.IntegrationSuite.SetUpTest(c)
 
 	// Install the gitolite hooks in the bare repo we made in
-	// s.serverSuite.SetUpTest() -- see 2.2.4 at
+	// (*IntegrationTest)SetUpTest() -- see 2.2.4 at
 	// http://gitolite.com/gitolite/gitolite.html
 	runGitolite("gitolite", "setup")
 
@@ -52,27 +52,31 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
 }
 
 func (s *GitoliteSuite) TearDownTest(c *check.C) {
-	s.serverSuite.TearDownTest(c)
+	// We really want Unsetenv here, but it's not worth forcing an
+	// upgrade to Go 1.4.
+	os.Setenv("GITOLITE_HTTP_HOME", "")
+	os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
+	s.IntegrationSuite.TearDownTest(c)
 }
 
 func (s *GitoliteSuite) TestFetch(c *check.C) {
-	err := s.serverSuite.runGit(c, activeToken, "fetch", "active/foo.git")
+	err := s.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")
+	err := s.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")
+	err := s.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",
+	sha1, err := exec.Command("git", "--git-dir", s.tmpWorkdir + "/.git",
 		"log", "-n1", "--format=%H").CombinedOutput()
 	c.Logf("git-log in workdir: %q", string(sha1))
 	c.Assert(err, check.Equals, nil)
@@ -84,6 +88,6 @@ func (s *GitoliteSuite) TestPush(c *check.C) {
 }
 
 func (s *GitoliteSuite) TestPushUnwritable(c *check.C) {
-	err := s.serverSuite.runGit(c, spectatorToken, "push", "active/foo.git")
+	err := s.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/integration_test.go
similarity index 51%
copy from services/arv-git-httpd/server_test.go
copy to services/arv-git-httpd/integration_test.go
index 7709dcc..61d83ff 100644
--- a/services/arv-git-httpd/server_test.go
+++ b/services/arv-git-httpd/integration_test.go
@@ -12,16 +12,13 @@ import (
 	check "gopkg.in/check.v1"
 )
 
-var _ = check.Suite(&IntegrationSuite{})
-
-const (
-	spectatorToken = "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu"
-	activeToken    = "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi"
-	anonymousToken = "4kg6k6lzmp9kj4cpkcoxie964cmvjahbt4fod9zru44k4jqdmi"
-	expiredToken   = "2ym314ysp27sk7h943q6vtc378srb06se3pq6ghurylyf3pdmx"
-)
+// Gocheck boilerplate
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
 
-// IntegrationSuite tests need an API server and an arv-git-httpd server
+// IntegrationSuite tests need an API server and an arv-git-httpd
+// server. See GitSuite and GitoliteSuite.
 type IntegrationSuite struct {
 	tmpRepoRoot string
 	tmpWorkdir  string
@@ -29,77 +26,6 @@ type IntegrationSuite struct {
 	Config      *config
 }
 
-func (s *IntegrationSuite) TestPathVariants(c *check.C) {
-	s.makeArvadosRepo(c)
-	for _, repo := range []string{"active/foo.git", "active/foo/.git", "arvados.git", "arvados/.git"} {
-		err := s.runGit(c, spectatorToken, "fetch", repo)
-		c.Assert(err, check.Equals, nil)
-	}
-}
-
-func (s *IntegrationSuite) TestReadonly(c *check.C) {
-	err := s.runGit(c, spectatorToken, "fetch", "active/foo.git")
-	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")
-	c.Assert(err, check.FitsTypeOf, &os.PathError{})
-}
-
-func (s *IntegrationSuite) TestReadwrite(c *check.C) {
-	err := s.runGit(c, activeToken, "fetch", "active/foo.git")
-	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")
-	c.Assert(err, check.Equals, nil)
-}
-
-func (s *IntegrationSuite) TestNonexistent(c *check.C) {
-	err := s.runGit(c, spectatorToken, "fetch", "thisrepodoesnotexist.git")
-	c.Assert(err, check.ErrorMatches, `.* not found.*`)
-}
-
-func (s *IntegrationSuite) TestMissingGitdirReadableRepository(c *check.C) {
-	err := s.runGit(c, activeToken, "fetch", "active/foo2.git")
-	c.Assert(err, check.ErrorMatches, `.* not found.*`)
-}
-
-func (s *IntegrationSuite) TestNoPermission(c *check.C) {
-	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, anonymousToken, "fetch", repo)
-		c.Assert(err, check.ErrorMatches, `.* not found.*`)
-	}
-}
-
-func (s *IntegrationSuite) TestExpiredToken(c *check.C) {
-	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, expiredToken, "fetch", repo)
-		c.Assert(err, check.ErrorMatches, `.* 500 while accessing.*`)
-	}
-}
-
-func (s *IntegrationSuite) TestInvalidToken(c *check.C) {
-	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, "s3cr3tp at ssw0rd", "fetch", repo)
-		c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
-	}
-}
-
-func (s *IntegrationSuite) TestShortToken(c *check.C) {
-	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, "s3cr3t", "fetch", repo)
-		c.Assert(err, check.ErrorMatches, `.* 500 while accessing.*`)
-	}
-}
-
-func (s *IntegrationSuite) TestShortTokenBadReq(c *check.C) {
-	for _, repo := range []string{"bogus"} {
-		err := s.runGit(c, "s3cr3t", "fetch", repo)
-		c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
-	}
-}
-
 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
 	arvadostest.StartAPI()
 }
@@ -179,7 +105,7 @@ func (s *IntegrationSuite) TearDownTest(c *check.C) {
 	s.Config = nil
 }
 
-func (s *IntegrationSuite) runGit(c *check.C, token, gitCmd, repo string, args ...string) error {
+func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error {
 	cwd, err := os.Getwd()
 	c.Assert(err, check.Equals, nil)
 	defer os.Chdir(cwd)
@@ -205,18 +131,3 @@ func (s *IntegrationSuite) runGit(c *check.C, token, gitCmd, repo string, args .
 	}
 	return err
 }
-
-// Make a bare arvados repo at {tmpRepoRoot}/arvados.git
-func (s *IntegrationSuite) makeArvadosRepo(c *check.C) {
-	msg, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").CombinedOutput()
-	c.Log(string(msg))
-	c.Assert(err, check.Equals, nil)
-	msg, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git", "fetch", "../../.git", "HEAD:master").CombinedOutput()
-	c.Log(string(msg))
-	c.Assert(err, check.Equals, nil)
-}
-
-// Gocheck boilerplate
-func Test(t *testing.T) {
-	check.TestingT(t)
-}
diff --git a/services/arv-git-httpd/server_test.go b/services/arv-git-httpd/server_test.go
index 7709dcc..2d1aeb7 100644
--- a/services/arv-git-httpd/server_test.go
+++ b/services/arv-git-httpd/server_test.go
@@ -1,18 +1,13 @@
 package main
 
 import (
-	"errors"
-	"io/ioutil"
 	"os"
 	"os/exec"
-	"strings"
-	"testing"
 
-	"git.curoverse.com/arvados.git/sdk/go/arvadostest"
 	check "gopkg.in/check.v1"
 )
 
-var _ = check.Suite(&IntegrationSuite{})
+var _ = check.Suite(&GitSuite{})
 
 const (
 	spectatorToken = "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu"
@@ -21,193 +16,83 @@ const (
 	expiredToken   = "2ym314ysp27sk7h943q6vtc378srb06se3pq6ghurylyf3pdmx"
 )
 
-// IntegrationSuite tests need an API server and an arv-git-httpd server
-type IntegrationSuite struct {
-	tmpRepoRoot string
-	tmpWorkdir  string
-	testServer  *server
-	Config      *config
+type GitSuite struct {
+	IntegrationSuite
 }
 
-func (s *IntegrationSuite) TestPathVariants(c *check.C) {
+func (s *GitSuite) TestPathVariants(c *check.C) {
 	s.makeArvadosRepo(c)
 	for _, repo := range []string{"active/foo.git", "active/foo/.git", "arvados.git", "arvados/.git"} {
-		err := s.runGit(c, spectatorToken, "fetch", repo)
+		err := s.RunGit(c, spectatorToken, "fetch", repo)
 		c.Assert(err, check.Equals, nil)
 	}
 }
 
-func (s *IntegrationSuite) TestReadonly(c *check.C) {
-	err := s.runGit(c, spectatorToken, "fetch", "active/foo.git")
+func (s *GitSuite) TestReadonly(c *check.C) {
+	err := s.RunGit(c, spectatorToken, "fetch", "active/foo.git")
 	c.Assert(err, check.Equals, nil)
-	err = s.runGit(c, spectatorToken, "push", "active/foo.git", "master:newbranchfail")
+	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")
 	c.Assert(err, check.FitsTypeOf, &os.PathError{})
 }
 
-func (s *IntegrationSuite) TestReadwrite(c *check.C) {
-	err := s.runGit(c, activeToken, "fetch", "active/foo.git")
+func (s *GitSuite) TestReadwrite(c *check.C) {
+	err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
 	c.Assert(err, check.Equals, nil)
-	err = s.runGit(c, activeToken, "push", "active/foo.git", "master:newbranch")
+	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")
 	c.Assert(err, check.Equals, nil)
 }
 
-func (s *IntegrationSuite) TestNonexistent(c *check.C) {
-	err := s.runGit(c, spectatorToken, "fetch", "thisrepodoesnotexist.git")
+func (s *GitSuite) TestNonexistent(c *check.C) {
+	err := s.RunGit(c, spectatorToken, "fetch", "thisrepodoesnotexist.git")
 	c.Assert(err, check.ErrorMatches, `.* not found.*`)
 }
 
-func (s *IntegrationSuite) TestMissingGitdirReadableRepository(c *check.C) {
-	err := s.runGit(c, activeToken, "fetch", "active/foo2.git")
+func (s *GitSuite) TestMissingGitdirReadableRepository(c *check.C) {
+	err := s.RunGit(c, activeToken, "fetch", "active/foo2.git")
 	c.Assert(err, check.ErrorMatches, `.* not found.*`)
 }
 
-func (s *IntegrationSuite) TestNoPermission(c *check.C) {
+func (s *GitSuite) TestNoPermission(c *check.C) {
 	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, anonymousToken, "fetch", repo)
+		err := s.RunGit(c, anonymousToken, "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* not found.*`)
 	}
 }
 
-func (s *IntegrationSuite) TestExpiredToken(c *check.C) {
+func (s *GitSuite) TestExpiredToken(c *check.C) {
 	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, expiredToken, "fetch", repo)
+		err := s.RunGit(c, expiredToken, "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* 500 while accessing.*`)
 	}
 }
 
-func (s *IntegrationSuite) TestInvalidToken(c *check.C) {
+func (s *GitSuite) TestInvalidToken(c *check.C) {
 	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, "s3cr3tp at ssw0rd", "fetch", repo)
+		err := s.RunGit(c, "s3cr3tp at ssw0rd", "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
 	}
 }
 
-func (s *IntegrationSuite) TestShortToken(c *check.C) {
+func (s *GitSuite) TestShortToken(c *check.C) {
 	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
-		err := s.runGit(c, "s3cr3t", "fetch", repo)
+		err := s.RunGit(c, "s3cr3t", "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* 500 while accessing.*`)
 	}
 }
 
-func (s *IntegrationSuite) TestShortTokenBadReq(c *check.C) {
+func (s *GitSuite) TestShortTokenBadReq(c *check.C) {
 	for _, repo := range []string{"bogus"} {
-		err := s.runGit(c, "s3cr3t", "fetch", repo)
+		err := s.RunGit(c, "s3cr3t", "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
 	}
 }
 
-func (s *IntegrationSuite) SetUpSuite(c *check.C) {
-	arvadostest.StartAPI()
-}
-
-func (s *IntegrationSuite) TearDownSuite(c *check.C) {
-	arvadostest.StopAPI()
-}
-
-func (s *IntegrationSuite) SetUpTest(c *check.C) {
-	arvadostest.ResetEnv()
-	s.testServer = &server{}
-	var err error
-	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", "--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)
-
-	_, err = exec.Command("git", "config",
-		"--file", s.tmpWorkdir+"/.git/config",
-		"credential.http://"+s.testServer.Addr+"/.helper",
-		"!cred(){ cat >/dev/null; if [ \"$1\" = get ]; then echo password=$ARVADOS_API_TOKEN; fi; };cred").Output()
-	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("git", "config",
-		"--file", s.tmpWorkdir+"/.git/config",
-		"credential.http://"+s.testServer.Addr+"/.username",
-		"none").Output()
-	c.Assert(err, check.Equals, nil)
-
-	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)
-
-	// Clear ARVADOS_API_TOKEN after starting up the server, to
-	// make sure arv-git-httpd doesn't use it.
-	os.Setenv("ARVADOS_API_TOKEN", "unused-token-placates-client-library")
-}
-
-func (s *IntegrationSuite) TearDownTest(c *check.C) {
-	var err error
-	if s.testServer != nil {
-		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 {
-	cwd, err := os.Getwd()
-	c.Assert(err, check.Equals, nil)
-	defer os.Chdir(cwd)
-	os.Chdir(s.tmpWorkdir)
-
-	gitargs := append([]string{
-		gitCmd, "http://" + s.testServer.Addr + "/" + repo,
-	}, args...)
-	cmd := exec.Command("git", gitargs...)
-	cmd.Env = append(os.Environ(), "ARVADOS_API_TOKEN="+token)
-	w, err := cmd.StdinPipe()
-	c.Assert(err, check.Equals, nil)
-	w.Close()
-	output, err := cmd.CombinedOutput()
-	c.Log("git ", gitargs, " => ", err)
-	c.Log(string(output))
-	if err != nil && len(output) > 0 {
-		// If messages appeared on stderr, they are more
-		// helpful than the err returned by CombinedOutput().
-		//
-		// Easier to match error strings without newlines:
-		err = errors.New(strings.Replace(string(output), "\n", " // ", -1))
-	}
-	return err
-}
-
 // Make a bare arvados repo at {tmpRepoRoot}/arvados.git
-func (s *IntegrationSuite) makeArvadosRepo(c *check.C) {
+func (s *GitSuite) makeArvadosRepo(c *check.C) {
 	msg, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").CombinedOutput()
 	c.Log(string(msg))
 	c.Assert(err, check.Equals, nil)
@@ -215,8 +100,3 @@ func (s *IntegrationSuite) makeArvadosRepo(c *check.C) {
 	c.Log(string(msg))
 	c.Assert(err, check.Equals, nil)
 }
-
-// Gocheck boilerplate
-func Test(t *testing.T) {
-	check.TestingT(t)
-}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list