-
Notifications
You must be signed in to change notification settings - Fork 4
/
config_test.go
45 lines (36 loc) · 1.06 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package flume
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
func TestConfigFromEnv(t *testing.T) {
// store the actual default factory, so we don't modify it
realPkgFactory := pkgFactory
realDefaultConfigVars := DefaultConfigEnvVars
origflume := os.Getenv("FLUME")
defer func() {
pkgFactory = realPkgFactory
DefaultConfigEnvVars = realDefaultConfigVars
os.Setenv("FLUME", origflume)
}()
pkgFactory = NewFactory()
// flume takes precedence
pkgFactory = NewFactory()
os.Setenv("FLUME", `{"levels":"yellow=DBG"}`)
require.NoError(t, ConfigFromEnv())
assert.Nil(t, pkgFactory.loggers["blue"])
assert.NotNil(t, pkgFactory.loggers["yellow"])
// custom args
pkgFactory = NewFactory()
v1 := "big_random_env_var_name_asdfasdfasdfasdfasdfasdfasd"
os.Unsetenv(v1)
defer os.Unsetenv(v1)
os.Setenv(v1, `{"levels":"pink=DBG"}`)
require.NoError(t, ConfigFromEnv(v1))
assert.NotNil(t, pkgFactory.loggers["pink"])
// bad value
os.Setenv(v1, `{"levels":"pink=DBG"`)
require.Error(t, ConfigFromEnv(v1))
}