14715: Moves legacy config test to lib/config
authorEric Biagiotti <ebiagiotti@veritasgenetics.com>
Wed, 14 Aug 2019 19:23:12 +0000 (15:23 -0400)
committerEric Biagiotti <ebiagiotti@veritasgenetics.com>
Wed, 14 Aug 2019 19:23:12 +0000 (15:23 -0400)
Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti@veritasgenetics.com>

lib/config/deprecated_test.go
services/keepproxy/keepproxy_test.go

index 8479842be9a3bf1255ff3777373b11468f7bbf8d..76313ebb1615885298b3c8109ea73515fcfa8f2f 100644 (file)
@@ -6,6 +6,7 @@ package config
 
 import (
        "flag"
+       "fmt"
        "io/ioutil"
        "os"
        "time"
@@ -14,6 +15,35 @@ import (
        check "gopkg.in/check.v1"
 )
 
+func testLoadLegacyConfig(content []byte, mungeFlag string, c *check.C) (*arvados.Cluster, error) {
+       tmpfile, err := ioutil.TempFile("", "example")
+       if err != nil {
+               return nil, err
+       }
+       defer os.Remove(tmpfile.Name())
+
+       if _, err := tmpfile.Write(content); err != nil {
+               return nil, err
+       }
+       if err := tmpfile.Close(); err != nil {
+               return nil, err
+       }
+       flags := flag.NewFlagSet("test", flag.ExitOnError)
+       ldr := testLoader(c, "Clusters: {zzzzz: {}}", nil)
+       ldr.SetupFlags(flags)
+       args := ldr.MungeLegacyConfigArgs(ldr.Logger, []string{"-config", tmpfile.Name()}, mungeFlag)
+       flags.Parse(args)
+       cfg, err := ldr.Load()
+       if err != nil {
+               return nil, err
+       }
+       cluster, err := cfg.GetCluster("")
+       if err != nil {
+               return nil, err
+       }
+       return cluster, nil
+}
+
 func (s *LoadSuite) TestDeprecatedNodeProfilesToServices(c *check.C) {
        hostname, err := os.Hostname()
        c.Assert(err, check.IsNil)
@@ -81,33 +111,8 @@ func (s *LoadSuite) TestLegacyKeepWebConfig(c *check.C) {
        "ManagementToken": "xyzzy"
 }
 `)
-       tmpfile, err := ioutil.TempFile("", "example")
-       if err != nil {
-               c.Error(err)
-       }
-       defer os.Remove(tmpfile.Name())
-
-       if _, err := tmpfile.Write(content); err != nil {
-               c.Error(err)
-       }
-       if err := tmpfile.Close(); err != nil {
-               c.Error(err)
-       }
-       flags := flag.NewFlagSet("keep-web", flag.ExitOnError)
-       ldr := testLoader(c, "Clusters: {zzzzz: {}}", nil)
-       ldr.SetupFlags(flags)
-       args := ldr.MungeLegacyConfigArgs(ldr.Logger, []string{"-config", tmpfile.Name()}, "-legacy-keepweb-config")
-       flags.Parse(args)
-       cfg, err := ldr.Load()
-       if err != nil {
-               c.Error(err)
-       }
-       c.Check(cfg, check.NotNil)
-       cluster, err := cfg.GetCluster("")
-       if err != nil {
-               c.Error(err)
-       }
-       c.Check(cluster, check.NotNil)
+       cluster, err := testLoadLegacyConfig(content, "-legacy-keepweb-config", c)
+       c.Check(err, check.IsNil)
 
        c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
        c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
@@ -127,3 +132,58 @@ func (s *LoadSuite) TestLegacyKeepWebConfig(c *check.C) {
        c.Check(cluster.Users.AnonymousUserToken, check.Equals, "anonusertoken")
        c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
 }
+
+func (s *LoadSuite) TestLegacyKeepproxyConfig(c *check.C) {
+       f := "-legacy-keepproxy-config"
+       content := []byte(fmtKeepproxyConfig("", true))
+       cluster, err := testLoadLegacyConfig(content, f, c)
+
+       c.Check(err, check.IsNil)
+       c.Check(cluster, check.NotNil)
+       c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
+       c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
+       c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
+       c.Check(cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: ":80"}], check.Equals, arvados.ServiceInstance{})
+       c.Check(cluster.Collections.DefaultReplication, check.Equals, 0)
+       c.Check(cluster.API.KeepServiceRequestTimeout.String(), check.Equals, "15s")
+       c.Check(cluster.SystemLogs.LogLevel, check.Equals, "debug")
+
+       content = []byte(fmtKeepproxyConfig("", false))
+       cluster, err = testLoadLegacyConfig(content, f, c)
+       c.Check(cluster.SystemLogs.LogLevel, check.Equals, "info")
+
+       content = []byte(fmtKeepproxyConfig(`"DisableGet": true,`, true))
+       _, err = testLoadLegacyConfig(content, f, c)
+       c.Check(err, check.NotNil)
+
+       content = []byte(fmtKeepproxyConfig(`"DisablePut": true,`, true))
+       _, err = testLoadLegacyConfig(content, f, c)
+       c.Check(err, check.NotNil)
+
+       content = []byte(fmtKeepproxyConfig(`"PIDFile": "test",`, true))
+       _, err = testLoadLegacyConfig(content, f, c)
+       c.Check(err, check.NotNil)
+
+       content = []byte(fmtKeepproxyConfig(`"DisableGet": false, "DisablePut": false, "PIDFile": "",`, true))
+       _, err = testLoadLegacyConfig(content, f, c)
+       c.Check(err, check.IsNil)
+}
+
+func fmtKeepproxyConfig(param string, debugLog bool) string {
+       return fmt.Sprintf(`
+{
+       "Client": {
+               "Scheme": "",
+               "APIHost": "example.com",
+               "AuthToken": "abcdefg",
+               "Insecure": false
+       },
+       "Listen": ":80",
+       "DefaultReplicas": 0,
+       "Timeout": "15s",
+       "Debug": %t,
+       %s
+       "ManagementToken": "xyzzy"
+}
+`, debugLog, param)
+}
index 609da4f7058dcc9b7a2aa5da98e1a3127dd990a8..d2758cc25f7ea3f92b35ec461f0d41c87958c72e 100644 (file)
@@ -13,7 +13,6 @@ import (
        "math/rand"
        "net/http"
        "net/http/httptest"
-       "os"
        "strings"
        "sync"
        "testing"
@@ -640,74 +639,3 @@ func (s *ServerRequiredSuite) TestPing(c *C) {
        c.Check(resp.Code, Equals, 200)
        c.Assert(resp.Body.String(), Matches, `{"health":"OK"}\n?`)
 }
-
-func (s *NoKeepServerSuite) TestLegacyConfig(c *C) {
-       content := []byte(fmtConfig("", true))
-       cluster, err := loadLegacyConfig(content, c)
-
-       c.Check(err, IsNil)
-       c.Check(cluster, NotNil)
-       c.Check(cluster.Services.Controller.ExternalURL, Equals, arvados.URL{Scheme: "https", Host: "example.com"})
-       c.Check(cluster.SystemRootToken, Equals, "abcdefg")
-       c.Check(cluster.ManagementToken, Equals, "xyzzy")
-       c.Check(cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: ":80"}], Equals, arvados.ServiceInstance{})
-       c.Check(cluster.Collections.DefaultReplication, Equals, 0)
-       c.Check(cluster.API.KeepServiceRequestTimeout.String(), Equals, "15s")
-       c.Check(cluster.SystemLogs.LogLevel, Equals, "debug")
-
-       content = []byte(fmtConfig("", false))
-       cluster, err = loadLegacyConfig(content, c)
-       c.Check(cluster.SystemLogs.LogLevel, Equals, "info")
-
-       content = []byte(fmtConfig(`"DisableGet": true,`, true))
-       _, err = loadLegacyConfig(content, c)
-       c.Check(err, NotNil)
-
-       content = []byte(fmtConfig(`"DisablePut": true,`, true))
-       _, err = loadLegacyConfig(content, c)
-       c.Check(err, NotNil)
-
-       content = []byte(fmtConfig(`"PIDFile": "test",`, true))
-       _, err = loadLegacyConfig(content, c)
-       c.Check(err, NotNil)
-
-       content = []byte(fmtConfig(`"DisableGet": false, "DisablePut": false, "PIDFile": "",`, true))
-       _, err = loadLegacyConfig(content, c)
-       c.Check(err, IsNil)
-
-}
-
-func loadLegacyConfig(content []byte, c *C) (*arvados.Cluster, error) {
-       tmpfile, err := ioutil.TempFile("", "example")
-       if err != nil {
-               c.Error(err)
-       }
-       defer os.Remove(tmpfile.Name())
-
-       if _, err := tmpfile.Write(content); err != nil {
-               c.Error(err)
-       }
-       if err := tmpfile.Close(); err != nil {
-               c.Error(err)
-       }
-       return configure(log.New(), []string{"keepproxy", "-config", tmpfile.Name()})
-}
-
-func fmtConfig(param string, debugLog bool) string {
-       return fmt.Sprintf(`
-{
-       "Client": {
-               "Scheme": "",
-               "APIHost": "example.com",
-               "AuthToken": "abcdefg",
-               "Insecure": false
-       },
-       "Listen": ":80",
-       "DefaultReplicas": 0,
-       "Timeout": "15s",
-       "Debug": %t,
-       %s
-       "ManagementToken": "xyzzy"
-}
-`, debugLog, param)
-}