Fix bug reading default value for combine_output

The default should be set to true so we maintain backwards.
compatibility.
readconfig.go was altered due to bug reading default value. This was
tested by adding unit tests to readconfig_test.go for positive and
negative scenarios.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (VMware) 2018-03-22 10:19:15 +00:00 committed by Alex Ellis
parent ae1279a553
commit a841e3d7f3
3 changed files with 29 additions and 5 deletions

View File

@ -4,9 +4,8 @@ WORKDIR /go/src/github.com/openfaas/faas/watchdog
COPY main.go .
COPY readconfig.go .
COPY config_test.go .
COPY readconfig_test.go .
COPY requesthandler_test.go .
COPY types types
# Run a gofmt and exclude all vendored code.

View File

@ -87,7 +87,7 @@ func (ReadConfig) Read(hasEnv HasEnv) WatchdogConfig {
cfg.contentType = hasEnv.Getenv("content_type")
if isBoolValueSet("combine_output") {
if isBoolValueSet(hasEnv.Getenv("combine_output")) {
cfg.combineOutput = parseBoolValue(hasEnv.Getenv("combine_output"))
}

View File

@ -26,6 +26,31 @@ func (e EnvBucket) Setenv(key string, value string) {
e.Items[key] = value
}
func TestRead_CombineOutput_DefaultTrue(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
config := readConfig.Read(defaults)
want := true
if config.combineOutput != want {
t.Logf("combineOutput error, want: %v, got: %v", want, config.combineOutput)
t.Fail()
}
}
func TestRead_CombineOutput_OverrideFalse(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
defaults.Setenv("combine_output", "false")
config := readConfig.Read(defaults)
want := false
if config.combineOutput != want {
t.Logf("combineOutput error, want: %v, got: %v", want, config.combineOutput)
t.Fail()
}
}
func TestRead_CgiHeaders_OverrideFalse(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}