From a841e3d7f3ba04c432575953b7a9ee06961e94f6 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" Date: Thu, 22 Mar 2018 10:19:15 +0000 Subject: [PATCH] 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) --- watchdog/Dockerfile | 7 +++--- watchdog/readconfig.go | 2 +- .../{config_test.go => readconfig_test.go} | 25 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) rename watchdog/{config_test.go => readconfig_test.go} (89%) diff --git a/watchdog/Dockerfile b/watchdog/Dockerfile index 3205ee5c..8794f412 100644 --- a/watchdog/Dockerfile +++ b/watchdog/Dockerfile @@ -2,11 +2,10 @@ FROM golang:1.8.5 RUN mkdir -p /go/src/github.com/openfaas/faas/watchdog WORKDIR /go/src/github.com/openfaas/faas/watchdog -COPY main.go . -COPY readconfig.go . -COPY config_test.go . +COPY main.go . +COPY readconfig.go . +COPY readconfig_test.go . COPY requesthandler_test.go . - COPY types types # Run a gofmt and exclude all vendored code. diff --git a/watchdog/readconfig.go b/watchdog/readconfig.go index d8a1f760..d36a3f5f 100644 --- a/watchdog/readconfig.go +++ b/watchdog/readconfig.go @@ -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")) } diff --git a/watchdog/config_test.go b/watchdog/readconfig_test.go similarity index 89% rename from watchdog/config_test.go rename to watchdog/readconfig_test.go index 3c49c2d7..d61fc2df 100644 --- a/watchdog/config_test.go +++ b/watchdog/readconfig_test.go @@ -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{}