-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
60 lines (47 loc) · 1.64 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package config_test
import (
"embed"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/nrfta/go-config/v3"
)
//go:embed config_test.json
var fs embed.FS
type MyAppConfig struct {
Meta config.MetaConfig
Port int `mapstructure:"port"`
BugsnagAPIKey string `mapstructure:"bugsnag_api_key"`
LogLevel string `mapstructure:"log_level"`
PrometheusPort int `mapstructure:"prometheus_port"`
SegmentWriteKey string `mapstructure:"segment_write_key"`
}
var (
testConfig MyAppConfig
)
var _ = Describe("Test Load ", func() {
It("It should load config file", func() {
Expect(config.Load(fs, &testConfig)).To(Succeed())
Expect(testConfig.Meta.Environment).To(Equal("test"))
Expect(testConfig.Meta.ServiceName).To(Equal("my-app"))
Expect(testConfig.BugsnagAPIKey).To(Equal("test-key"))
Expect(testConfig.SegmentWriteKey).To(Equal("test-write-key"))
Expect(testConfig.LogLevel).To(Equal("error"))
Expect(testConfig.Port).To(Equal(6002))
})
})
var _ = Describe("Test Load With Environment Variables", func() {
It("It should load config file with environment variables", func() {
os.Setenv("PORT", "5001")
os.Setenv("META_SERVICE_NAME", "service-api")
Expect(config.Load(fs, &testConfig)).To(Succeed())
Expect(testConfig.Meta.Environment).To(Equal("test"))
Expect(testConfig.Meta.ServiceName).To(Equal("service-api"))
Expect(testConfig.BugsnagAPIKey).To(Equal("test-key"))
Expect(testConfig.SegmentWriteKey).To(Equal("test-write-key"))
Expect(testConfig.LogLevel).To(Equal("error"))
Expect(testConfig.Port).To(Equal(5001))
os.Unsetenv("PORT")
os.Unsetenv("META_SERVICE_NAME")
})
})