Skip to content

Commit

Permalink
Add test for coverage.
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffrey Huck <[email protected]>
  • Loading branch information
GeoffreyHuck committed Jun 12, 2024
1 parent ea82c55 commit efc898f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/config_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package app

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -65,6 +67,31 @@ func TestLoadConfigFrom(t *testing.T) {
assert.EqualValues(777, conf.GetInt("server.WriteTimeout"))
}

func TestLoadConfigFrom_ShouldLogWarningWhenNonTestEnvAndNoMainConfigFile(t *testing.T) {
assert := assertlib.New(t)

var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()

monkey.Patch(appenv.Env, func() string { return devEnv })
monkey.Patch(appenv.IsEnvTest, func() bool { return false })
defer monkey.UnpatchAll()

// create a temp config file
tmpFile, deferFunc := createTmpFile("config-*.dev.yaml", assert)
defer deferFunc()

fileName := filepath.Base(tmpFile.Name())
configName := fileName[:len(fileName)-8] // strip the ".dev.yaml"

conf := loadConfigFrom(configName, os.TempDir())
assert.NotNil(conf)
assert.Contains(buf.String(), "Cannot read the main config file, ignoring it")
}

func TestLoadConfigFrom_IgnoresMainConfigFileIfMissing(t *testing.T) {
assert := assertlib.New(t)
appenv.SetDefaultEnvToTest() // to ensure it tries to find the config.test file
Expand Down

0 comments on commit efc898f

Please sign in to comment.