diff options
author | Paul Okstad <pokstad@gitlab.com> | 2019-06-08 00:27:17 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2019-06-08 00:27:17 +0300 |
commit | 4e9a7dccc2608b6017d6b6a9e90b161fc2d03437 (patch) | |
tree | 967e7c65e0a20f5b6764251dbb210f60c03e6c57 | |
parent | 209b3635b8b21090f105356727a953d28d84f404 (diff) | |
parent | c1073b146db4391c5622e0da72f5d92ac4e61375 (diff) |
Merge branch 'jv-export-config' into 'master'
Export config struct type
See merge request gitlab-org/gitaly!1295
-rw-r--r-- | internal/config/config.go | 9 | ||||
-rw-r--r-- | internal/config/config_test.go | 22 |
2 files changed, 16 insertions, 15 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index e0bcdb98f..156da2bbd 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -23,12 +23,13 @@ const ( var ( // Config stores the global configuration - Config config + Config Cfg hooks []func() error ) -type config struct { +// Cfg is a container for all config derived from config.toml. +type Cfg struct { SocketPath string `toml:"socket_path" split_words:"true"` ListenAddr string `toml:"listen_addr" split_words:"true"` TLSListenAddr string `toml:"tls_listen_addr" split_words:"true"` @@ -105,7 +106,7 @@ type Concurrency struct { // Load initializes the Config variable from file and the environment. // Environment variables take precedence over the file. func Load(file io.Reader) error { - Config = config{} + Config = Cfg{} if _, err := toml.DecodeReader(file, &Config); err != nil { return fmt.Errorf("load toml: %v", err) @@ -150,7 +151,7 @@ func Validate() error { return nil } -func (c *config) setDefaults() { +func (c *Cfg) setDefaults() { c.GracefulRestartTimeout = c.GracefulRestartTimeoutToml.Duration if c.GracefulRestartTimeout == 0 { c.GracefulRestartTimeout = 1 * time.Minute diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 9d12a2a2d..36cc77276 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -21,7 +21,7 @@ func configFileReader(content string) io.Reader { } func TestLoadClearPrevConfig(t *testing.T) { - Config = config{SocketPath: "/tmp"} + Config = Cfg{SocketPath: "/tmp"} err := Load(&bytes.Buffer{}) assert.NoError(t, err) @@ -33,7 +33,7 @@ func TestLoadBrokenConfig(t *testing.T) { err := Load(tmpFile) assert.Error(t, err) - assert.Equal(t, config{}, Config) + assert.Equal(t, Cfg{}, Config) } func TestLoadEmptyConfig(t *testing.T) { @@ -42,7 +42,7 @@ func TestLoadEmptyConfig(t *testing.T) { err := Load(tmpFile) assert.NoError(t, err) - defaultConf := config{} + defaultConf := Cfg{} defaultConf.setDefaults() assert.Equal(t, defaultConf, Config) @@ -57,7 +57,7 @@ path = "/tmp"`) assert.NoError(t, err) if assert.Equal(t, 1, len(Config.Storages), "Expected one (1) storage") { - expectedConf := config{ + expectedConf := Cfg{ Storages: []Storage{ {Name: "default", Path: "/tmp"}, }, @@ -81,7 +81,7 @@ path="/tmp/repos2"`) assert.NoError(t, err) if assert.Equal(t, 2, len(Config.Storages), "Expected one (1) storage") { - expectedConf := config{ + expectedConf := Cfg{ Storages: []Storage{ {Name: "default", Path: "/tmp/repos1"}, {Name: "other", Path: "/tmp/repos2"}, @@ -476,24 +476,24 @@ func TestConfigureRubyNumWorkers(t *testing.T) { } func TestValidateListeners(t *testing.T) { - defer func(cfg config) { + defer func(cfg Cfg) { Config = cfg }(Config) testCases := []struct { desc string - config + Cfg ok bool }{ {desc: "empty"}, - {desc: "socket only", config: config{SocketPath: "/foo/bar"}, ok: true}, - {desc: "tcp only", config: config{ListenAddr: "a.b.c.d:1234"}, ok: true}, - {desc: "both socket and tcp", config: config{SocketPath: "/foo/bar", ListenAddr: "a.b.c.d:1234"}, ok: true}, + {desc: "socket only", Cfg: Cfg{SocketPath: "/foo/bar"}, ok: true}, + {desc: "tcp only", Cfg: Cfg{ListenAddr: "a.b.c.d:1234"}, ok: true}, + {desc: "both socket and tcp", Cfg: Cfg{SocketPath: "/foo/bar", ListenAddr: "a.b.c.d:1234"}, ok: true}, } for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - Config = tc.config + Config = tc.Cfg err := validateListeners() if tc.ok { require.NoError(t, err) |