-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurer_test.go
77 lines (64 loc) · 1.61 KB
/
configurer_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
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
package qgoconf
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// `mapstructure:",squash"` is required for embedded structs
type testConfig struct {
BaseConfig `mapstructure:"core"`
Name string
}
type AnotherConfig struct {
Desc string
Misc string
Name string
}
var testConfigInstance = testConfig{
BaseConfig: BaseConfig{
DB: DBConfig{
Driver: "sqlite",
DSN: "./test.db",
},
HTTP: HTTPConfig{
Address: ":8080",
},
LogLevel: "info",
},
Name: "Test Config",
}
var AnotherConfigInstance = &AnotherConfig{
Desc: "desc",
Misc: DefaultConfigFile,
Name: EvnPrefix,
}
// Test Default Configuration
func TestReadConfigurationFromModelAndWriteToFile(t *testing.T) {
appconfig := DefaultAppConfig
_ = appconfig.AddJsonConfig(testConfigInstance)
//_ = appconfig.AddJsonConfig(AnotherConfigInstance)
appconfig.WriteConfig("config.yaml")
}
type NamedMan struct {
Kevin string
Smith string
}
func TestReadConfigurationFromFileAndWriteToStruct(t *testing.T) {
appconfig, _ := NewYamlConfig("config.yaml")
result := appconfig.Viper.Get("name")
assert.Equal(t, "FLUENT", result)
named := &NamedMan{}
appconfig.ToStruct(AnotherConfigInstance)
appconfig.ToStructByKey("nested", named)
fmt.Println(named.Kevin)
fmt.Println(named.Smith)
assert.Equal(t, "FLUENT", AnotherConfigInstance.Name)
assert.Equal(t, DefaultConfigFile, AnotherConfigInstance.Misc)
}
func TestReadConfigurationFromFileAndWriteToFile(t *testing.T) {
appconfig, _ := NewYamlConfig("config.yaml")
config := &testConfig{}
fmt.Println(appconfig.Viper.Get("db"))
appconfig.ToStruct(config)
fmt.Println(config)
}