-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
81 lines (67 loc) · 1.81 KB
/
Copy pathconfig_test.go
File metadata and controls
81 lines (67 loc) · 1.81 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package valkyrie
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type constants struct {
App struct {
Name string `yaml:"name"`
Port int `yaml:"port"`
ReadTimeout int `yaml:"read_timeout"`
WriteTimeout int `yaml:"write_timeout"`
Timezone string `yaml:"timezone"`
Debug bool `yaml:"debug"`
Env string `yaml:"env"`
SecretKey string `yaml:"secret_key"`
ExpireIn *time.Duration `yaml:"expire_in"`
} `yaml:"App"`
DB struct {
DsnMain string `yaml:"dsn_main" env:"DSN_MAIN"`
}
}
func TestConfig(t *testing.T) {
var cfg constants
err := Config(ConfigOpts{
Config: &cfg,
Filenames: []string{"app.test.yaml"},
Paths: []string{".", "./config"},
})
assert.Error(t, err)
assert.Equal(t, 8778, cfg.App.Port)
}
func TestConfigPathFail(t *testing.T) {
var cfg constants
err := Config(ConfigOpts{
Config: &cfg,
Filenames: []string{"app.test.yaml"},
Paths: []string{"./config"},
})
assert.Error(t, err)
}
func TestConfigEnv(t *testing.T) {
defer os.Clearenv()
var cfg constants
val := "host=localhost port=5999 user=root password=root123 dbname=dbroot sslmode=disable"
err := Config(ConfigOpts{
Config: &cfg,
Filenames: []string{"app.test.yaml"},
Paths: []string{".", "./config"},
})
assert.Error(t, err)
assert.Equal(t, val, cfg.DB.DsnMain)
}
func TestConfigFunc(t *testing.T) {
defer os.Clearenv()
var cfg constants
val := "host=localhost port=5999 user=root password=root123 dbname=dbroot sslmode=disable"
_ = os.Setenv("DSN_MAIN", val)
err := Config(ConfigOpts{
Config: &cfg,
Filenames: []string{"app.test.yaml"},
Paths: []string{".", "./config"},
})
assert.Error(t, err)
assert.Equal(t, val, cfg.DB.DsnMain)
}