-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader_test.go
51 lines (41 loc) · 905 Bytes
/
loader_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
46
47
48
49
50
51
//
package config_loader
import (
"os"
"testing"
)
type BasicConfig struct {
Username string `json:"username"`
Act string `default:"holo***"`
}
func TestLoadConfig(t *testing.T) {
config := &BasicConfig{}
err := Load(config, ConfigPath("basic_config.json"))
if err != nil {
t.Fatal(err)
}
if config.Username != "admin" {
t.Fatal("username not set correctly")
}
}
func TestEnvOverrides(t *testing.T) {
os.Setenv("TEST_USERNAME", "test_admin")
config := &BasicConfig{}
err := Load(config, ConfigPath("basic_config.json"), EnvPrefix("TEST"))
if err != nil {
t.Fatal(err)
}
if config.Username != "test_admin" {
t.Fatal("username not set correctly")
}
}
func TestDefaultValues(t *testing.T) {
config := &BasicConfig{}
err := Load(config)
if err != nil {
t.Fatal(err)
}
if config.Act != "holo***" {
t.Fatal("username not set correctly: " + config.Username)
}
}