From a5db96feced74279d61fe8254ed38a321342da1d Mon Sep 17 00:00:00 2001 From: Eric Biagiotti Date: Mon, 26 Aug 2019 10:44:23 -0400 Subject: [PATCH] 14712: Fixes tests Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti --- services/arv-git-httpd/auth_handler_test.go | 21 ++++++----- services/arv-git-httpd/git_handler_test.go | 24 ++++++++---- services/arv-git-httpd/gitolite_test.go | 24 ++++++------ services/arv-git-httpd/integration_test.go | 41 +++++++++++---------- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/services/arv-git-httpd/auth_handler_test.go b/services/arv-git-httpd/auth_handler_test.go index 05fde03e72..a8fb3acd43 100644 --- a/services/arv-git-httpd/auth_handler_test.go +++ b/services/arv-git-httpd/auth_handler_test.go @@ -13,6 +13,7 @@ import ( "path/filepath" "strings" + "git.curoverse.com/arvados.git/lib/config" "git.curoverse.com/arvados.git/sdk/go/arvados" "git.curoverse.com/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" @@ -34,16 +35,16 @@ func (s *AuthHandlerSuite) SetUpTest(c *check.C) { arvadostest.ResetEnv() repoRoot, err := filepath.Abs("../api/tmp/git/test") c.Assert(err, check.IsNil) - theConfig = &Config{ - Client: arvados.Client{ - APIHost: arvadostest.APIHost(), - Insecure: true, - }, - Listen: ":0", - GitCommand: "/usr/bin/git", - RepoRoot: repoRoot, - ManagementToken: arvadostest.ManagementToken, - } + + cfg, err := config.NewLoader(nil, nil).Load() + c.Assert(err, check.Equals, nil) + cluster, err := cfg.GetCluster("") + c.Assert(err, check.Equals, nil) + + cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{arvados.URL{Host: "localhost:0"}: arvados.ServiceInstance{}} + cluster.TLS.Insecure = true + cluster.Git.GitCommand = "/usr/bin/git" + cluster.Git.Repositories = repoRoot } func (s *AuthHandlerSuite) TestPermission(c *check.C) { diff --git a/services/arv-git-httpd/git_handler_test.go b/services/arv-git-httpd/git_handler_test.go index 0cf7de4e22..8417b57e4d 100644 --- a/services/arv-git-httpd/git_handler_test.go +++ b/services/arv-git-httpd/git_handler_test.go @@ -10,17 +10,27 @@ import ( "net/url" "regexp" + "git.curoverse.com/arvados.git/lib/config" + "git.curoverse.com/arvados.git/sdk/go/arvados" check "gopkg.in/check.v1" ) var _ = check.Suite(&GitHandlerSuite{}) -type GitHandlerSuite struct{} +type GitHandlerSuite struct { + cluster *arvados.Cluster +} func (s *GitHandlerSuite) TestEnvVars(c *check.C) { - theConfig = defaultConfig() - theConfig.RepoRoot = "/" - theConfig.GitoliteHome = "/test/ghh" + + cfg, err := config.NewLoader(nil, nil).Load() + c.Assert(err, check.Equals, nil) + s.cluster, err = cfg.GetCluster("") + c.Assert(err, check.Equals, nil) + + s.cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{arvados.URL{Host: "localhost:80"}: arvados.ServiceInstance{}} + s.cluster.Git.GitoliteHome = "/test/ghh" + s.cluster.Git.Repositories = "/" u, err := url.Parse("git.zzzzz.arvadosapi.com/test") c.Check(err, check.Equals, nil) @@ -30,7 +40,7 @@ func (s *GitHandlerSuite) TestEnvVars(c *check.C) { URL: u, RemoteAddr: "[::1]:12345", } - h := newGitHandler() + h := newGitHandler(s.cluster) h.(*gitHandler).Path = "/bin/sh" h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"} @@ -43,7 +53,7 @@ func (s *GitHandlerSuite) TestEnvVars(c *check.C) { c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`) c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`) c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`) - c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`) + c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta("localhost:80")+`$.*`) } func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) { @@ -55,7 +65,7 @@ func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) { URL: u, RemoteAddr: "test.bad.address.missing.port", } - h := newGitHandler() + h := newGitHandler(s.cluster) h.ServeHTTP(resp, req) c.Check(resp.Code, check.Equals, http.StatusInternalServerError) c.Check(resp.Body.String(), check.Equals, "") diff --git a/services/arv-git-httpd/gitolite_test.go b/services/arv-git-httpd/gitolite_test.go index 88cd221cbf..eaa7b55f83 100644 --- a/services/arv-git-httpd/gitolite_test.go +++ b/services/arv-git-httpd/gitolite_test.go @@ -10,8 +10,8 @@ import ( "os/exec" "strings" + "git.curoverse.com/arvados.git/lib/config" "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" ) @@ -47,16 +47,18 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) { runGitolite("gitolite", "setup", "--admin", "root") s.tmpRepoRoot = s.gitoliteHome + "/repositories" - s.Config = &Config{ - Client: arvados.Client{ - APIHost: arvadostest.APIHost(), - Insecure: true, - }, - Listen: "localhost:0", - GitCommand: "/usr/share/gitolite3/gitolite-shell", - GitoliteHome: s.gitoliteHome, - RepoRoot: s.tmpRepoRoot, - } + + cfg, err := config.NewLoader(nil, nil).Load() + c.Assert(err, check.Equals, nil) + s.cluster, err = cfg.GetCluster("") + c.Assert(err, check.Equals, nil) + + s.cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{arvados.URL{Host: "localhost:0"}: arvados.ServiceInstance{}} + s.cluster.TLS.Insecure = true + s.cluster.Git.GitCommand = "/usr/share/gitolite3/gitolite-shell" + s.cluster.Git.GitoliteHome = s.gitoliteHome + s.cluster.Git.Repositories = s.tmpRepoRoot + s.IntegrationSuite.SetUpTest(c) // Install the gitolite hooks in the bare repo we made in diff --git a/services/arv-git-httpd/integration_test.go b/services/arv-git-httpd/integration_test.go index 53b636dc0e..a6f114140f 100644 --- a/services/arv-git-httpd/integration_test.go +++ b/services/arv-git-httpd/integration_test.go @@ -12,6 +12,7 @@ import ( "strings" "testing" + "git.curoverse.com/arvados.git/lib/config" "git.curoverse.com/arvados.git/sdk/go/arvados" "git.curoverse.com/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" @@ -28,7 +29,7 @@ type IntegrationSuite struct { tmpRepoRoot string tmpWorkdir string testServer *server - Config *Config + cluster *arvados.Cluster } func (s *IntegrationSuite) SetUpSuite(c *check.C) { @@ -41,7 +42,7 @@ func (s *IntegrationSuite) TearDownSuite(c *check.C) { 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") @@ -71,19 +72,6 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) { "none").Output() c.Assert(err, check.Equals, nil) - if s.Config == nil { - s.Config = &Config{ - Client: arvados.Client{ - APIHost: arvadostest.APIHost(), - Insecure: true, - }, - Listen: "localhost:0", - GitCommand: "/usr/bin/git", - RepoRoot: s.tmpRepoRoot, - ManagementToken: arvadostest.ManagementToken, - } - } - // Clear ARVADOS_API_* env vars before starting up the server, // to make sure arv-git-httpd doesn't use them or complain // about them being missing. @@ -91,7 +79,24 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) { os.Unsetenv("ARVADOS_API_HOST_INSECURE") os.Unsetenv("ARVADOS_API_TOKEN") - theConfig = s.Config + cfg, err := config.NewLoader(nil, nil).Load() + c.Assert(err, check.Equals, nil) + s.cluster, err = cfg.GetCluster("") + c.Assert(err, check.Equals, nil) + + if s.cluster == nil { + s.cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{arvados.URL{Host: "localhost:0"}: arvados.ServiceInstance{}} + s.cluster.TLS.Insecure = true + s.cluster.Git.GitCommand = "/usr/bin/git" + s.cluster.Git.Repositories = s.tmpRepoRoot + } + + println(s.cluster.Services.Controller.InternalURLs) + println(arvadostest.APIHost()) + println(s.cluster.ManagementToken) + println(arvadostest.ManagementToken) + + s.testServer = &server{cluster: s.cluster} err = s.testServer.Start() c.Assert(err, check.Equals, nil) } @@ -116,9 +121,7 @@ func (s *IntegrationSuite) TearDownTest(c *check.C) { } s.tmpWorkdir = "" - s.Config = nil - - theConfig = defaultConfig() + s.cluster = nil } func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error { -- 2.30.2