diff options
author | Nick Thomas <nick@gitlab.com> | 2019-01-15 23:36:21 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-01-15 23:36:21 +0000 |
commit | 1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258 (patch) | |
tree | c246e5b43a1e7b5744e10e75d6ed125629f45936 /go/internal/config/config_test.go | |
parent | 6c5b195353a632095d7f672d28b9985fd879b077 (diff) | |
parent | d762f4ec9ea35cb00309b41ad60055cd3c5709ba (diff) | |
download | gitlab-shell-1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258.tar.gz |
Merge branch 'bvl-feature-flag-commands' into 'master'
Parse commands to enable feature flags
See merge request gitlab-org/gitlab-shell!270
Diffstat (limited to 'go/internal/config/config_test.go')
-rw-r--r-- | go/internal/config/config_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/go/internal/config/config_test.go b/go/internal/config/config_test.go index 87a582f..6640f42 100644 --- a/go/internal/config/config_test.go +++ b/go/internal/config/config_test.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" "testing" + + "github.com/stretchr/testify/assert" ) func TestParseConfig(t *testing.T) { @@ -12,6 +14,7 @@ func TestParseConfig(t *testing.T) { yaml string path string format string + gitlabUrl string migration MigrationConfig }{ {path: "/foo/bar/gitlab-shell.log", format: "text"}, @@ -24,6 +27,12 @@ func TestParseConfig(t *testing.T) { format: "text", migration: MigrationConfig{Enabled: true, Features: []string{"foo", "bar"}}, }, + { + yaml: "gitlab_url: http+unix://%2Fpath%2Fto%2Fgitlab%2Fgitlab.socket", + path: "/foo/bar/gitlab-shell.log", + format: "text", + gitlabUrl: "http+unix:///path/to/gitlab/gitlab.socket", + }, } for _, tc := range testCases { @@ -48,6 +57,60 @@ func TestParseConfig(t *testing.T) { if cfg.LogFormat != tc.format { t.Fatalf("expected %q, got %q", tc.format, cfg.LogFormat) } + + assert.Equal(t, tc.gitlabUrl, cfg.GitlabUrl) + }) + } +} + +func TestFeatureEnabled(t *testing.T) { + testCases := []struct { + desc string + config *Config + feature string + expectEnabled bool + }{ + { + desc: "When the protocol is supported and the feature enabled", + config: &Config{ + GitlabUrl: "http+unix://gitlab.socket", + Migration: MigrationConfig{Enabled: true, Features: []string{"discover"}}, + }, + feature: "discover", + expectEnabled: true, + }, + { + desc: "When the protocol is supported and the feature is not enabled", + config: &Config{ + GitlabUrl: "http+unix://gitlab.socket", + Migration: MigrationConfig{Enabled: true, Features: []string{}}, + }, + feature: "discover", + expectEnabled: false, + }, + { + desc: "When the protocol is supported and all features are disabled", + config: &Config{ + GitlabUrl: "http+unix://gitlab.socket", + Migration: MigrationConfig{Enabled: false, Features: []string{"discover"}}, + }, + feature: "discover", + expectEnabled: false, + }, + { + desc: "When the protocol is not supported", + config: &Config{ + GitlabUrl: "https://localhost:3000", + Migration: MigrationConfig{Enabled: true, Features: []string{"discover"}}, + }, + feature: "discover", + expectEnabled: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.desc, func(t *testing.T) { + assert.Equal(t, tc.expectEnabled, tc.config.FeatureEnabled(string(tc.feature))) }) } } |