17217: Remove crufty test util funcs.
[arvados.git] / services / arv-git-httpd / integration_test.go
index 1d252599cdf3078b9924318980d91e031feb687d..93a46e22482380bc57162c01d18727fbe0250274 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -8,8 +12,10 @@ import (
        "strings"
        "testing"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/lib/config"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
+       "git.arvados.org/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/ctxlog"
        check "gopkg.in/check.v1"
 )
 
@@ -24,20 +30,12 @@ type IntegrationSuite struct {
        tmpRepoRoot string
        tmpWorkdir  string
        testServer  *server
-       Config      *Config
-}
-
-func (s *IntegrationSuite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
-}
-
-func (s *IntegrationSuite) TearDownSuite(c *check.C) {
-       arvadostest.StopAPI()
+       cluster     *arvados.Cluster
 }
 
 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")
@@ -47,15 +45,35 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
        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)
+       // we need git 2.28 to specify the initial branch with -b; Buster only has 2.20; so we do it in 2 steps
        _, err = exec.Command("git", "init", s.tmpWorkdir).Output()
        c.Assert(err, check.Equals, nil)
+       _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && git checkout -b main").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()
+       _, err = exec.Command("sh", "-c", "cd "+s.tmpWorkdir+" && git push "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666.git main:main").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)
 
+       if s.cluster == nil {
+               cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).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{{Host: "localhost:0"}: {}}
+               s.cluster.TLS.Insecure = true
+               s.cluster.Git.GitCommand = "/usr/bin/git"
+               s.cluster.Git.Repositories = s.tmpRepoRoot
+               s.cluster.ManagementToken = arvadostest.ManagementToken
+       }
+
+       s.testServer = &server{cluster: s.cluster}
+       err = s.testServer.Start()
+       c.Assert(err, check.Equals, nil)
+
        _, err = exec.Command("git", "config",
                "--file", s.tmpWorkdir+"/.git/config",
                "credential.http://"+s.testServer.Addr+"/.helper",
@@ -67,28 +85,12 @@ 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:     ":0",
-                       GitCommand: "/usr/bin/git",
-                       RepoRoot:   s.tmpRepoRoot,
-               }
-       }
-
        // 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.
        os.Unsetenv("ARVADOS_API_HOST")
        os.Unsetenv("ARVADOS_API_HOST_INSECURE")
        os.Unsetenv("ARVADOS_API_TOKEN")
-
-       theConfig = s.Config
-       err = s.testServer.Start()
-       c.Assert(err, check.Equals, nil)
 }
 
 func (s *IntegrationSuite) TearDownTest(c *check.C) {
@@ -111,9 +113,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 {