14712: Fixes tests
authorEric Biagiotti <ebiagiotti@veritasgenetics.com>
Mon, 26 Aug 2019 14:44:23 +0000 (10:44 -0400)
committerEric Biagiotti <ebiagiotti@veritasgenetics.com>
Mon, 26 Aug 2019 15:58:34 +0000 (11:58 -0400)
Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti@veritasgenetics.com>

services/arv-git-httpd/auth_handler_test.go
services/arv-git-httpd/git_handler_test.go
services/arv-git-httpd/gitolite_test.go
services/arv-git-httpd/integration_test.go

index 05fde03e72c7366ebafdf7e1fc04209e86c5868e..a8fb3acd43de8e1abc8dd2c302f042c8f287d482 100644 (file)
@@ -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) {
index 0cf7de4e22c229545bde64edaa03aa9dcb2612a6..8417b57e4d96743fbccdc88893a8e8ec18723f05 100644 (file)
@@ -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, "")
index 88cd221cbf8aaed87e4f91a6289e8dd02458cd90..eaa7b55f8381f0b4097d751b2aad39866babe355 100644 (file)
@@ -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
index 53b636dc0e577e75bf5577e66a54059628be8774..a6f114140fb496404d721542a72ecbe6d213d397 100644 (file)
@@ -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 {