-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig_test.go
48 lines (43 loc) · 1008 Bytes
/
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
package dependencies
import (
"os"
"testing"
"github.com/jessevdk/go-flags"
"github.com/stretchr/testify/assert"
)
func TestInitConfig(t *testing.T) {
_, err := initConfig()
assert.NoError(t, err)
}
func TestConfig(t *testing.T) {
testCases := []struct {
name string
test func(t *testing.T)
}{
{
name: "Ok env",
test: func(t *testing.T) {
err := os.Setenv("NP_API_KEY", "test_key")
assert.NoError(t, err)
config, err := initConfig()
assert.NoError(t, err)
assert.Equal(t, "test_key", config.NovaPoshta.ApiKey)
},
},
{
name: "Ok flag",
test: func(t *testing.T) {
config := &Config{}
parser := flags.NewParser(config, flags.Default&^flags.PrintErrors)
_, err := parser.ParseArgs([]string{"--ME_PASSWORD=test_password"})
assert.NoError(t, err)
assert.Equal(t, "test_password", config.MeestExpress.Password)
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
testCase.test(t)
})
}
}