diff options
author | Nick Thomas <nick@gitlab.com> | 2018-09-28 15:17:17 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-09-28 15:24:45 +0100 |
commit | f435c4644abc167cdfe6bfe3d320ff840f468c09 (patch) | |
tree | c4b4754790e619082ca935cef0bb489f3a6470b6 /go/internal/config | |
parent | 7f1098a1d9fd79b394b53b0c43fcc4741349d43a (diff) | |
download | gitlab-shell-f435c4644abc167cdfe6bfe3d320ff840f468c09.tar.gz |
Allow the config directory to be specified
Diffstat (limited to 'go/internal/config')
-rw-r--r-- | go/internal/config/config.go | 19 | ||||
-rw-r--r-- | go/internal/config/config_test.go | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/go/internal/config/config.go b/go/internal/config/config.go index 4069851..435cb29 100644 --- a/go/internal/config/config.go +++ b/go/internal/config/config.go @@ -26,24 +26,31 @@ type Config struct { } func New() (*Config, error) { - cfg := Config{} - dir, err := os.Getwd() if err != nil { return nil, err } - cfg.RootDir = dir - configBytes, err := ioutil.ReadFile(path.Join(cfg.RootDir, configFile)) + return NewFromDir(dir) +} + +func NewFromDir(dir string) (*Config, error) { + return newFromFile(path.Join(dir, configFile)) +} + +func newFromFile(filename string) (*Config, error) { + cfg := &Config{RootDir: path.Dir(filename)} + + configBytes, err := ioutil.ReadFile(filename) if err != nil { return nil, err } - if err := parseConfig(configBytes, &cfg); err != nil { + if err := parseConfig(configBytes, cfg); err != nil { return nil, err } - return &cfg, nil + return cfg, nil } // parseConfig expects YAML data in configBytes and a Config instance with RootDir set. diff --git a/go/internal/config/config_test.go b/go/internal/config/config_test.go index 368ab29..87a582f 100644 --- a/go/internal/config/config_test.go +++ b/go/internal/config/config_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -func TestConfigLogFile(t *testing.T) { +func TestParseConfig(t *testing.T) { testRoot := "/foo/bar" testCases := []struct { yaml string |