-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig_test.go
71 lines (65 loc) · 1.94 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
61
62
63
64
65
66
67
68
69
70
71
package gonnect
import (
"io"
"strings"
"testing"
)
func TestNewConfig(t *testing.T) {
testCases := []struct {
Config io.Reader
Profile *Profile
profilename string
err error
}{
{
Config: strings.NewReader(`{"currentProfile": "dev", "profiles": {"dev": {"baseUrl": "http://test/","port": 8080,"store": {"type": "sqlite3",
"databaseUrl": "db.sqlite"}}}}`),
err: nil,
Profile: &Profile{
Port: 8080,
BaseUrl: "http://test/",
Store: StoreConfiguration{
Type: "sqlite3",
DatabaseUrl: "db.sqlite",
},
},
profilename: "dev",
},
{
Config: strings.NewReader(`{"profiles": {"prod": {"baseUrl": "http://test/","port": 8080,"store": {"type": "sqlite3",
"databaseUrl": "db.sqlite"}}}}`),
err: ErrConfigProfileNotFound,
Profile: nil,
profilename: "",
},
{
Config: strings.NewReader(`{"currentProfile":"dev","profiles": {"prod": {"baseUrl": "http://test/","port": 8080,"store": {"type": "sqlite3",
"databaseUrl": "db.sqlite"}}}}`),
err: ErrConfigProfileNotFound,
Profile: nil,
profilename: "",
},
{
Config: strings.NewReader(`{"currentProfile":"","profiles": {"prod": {"baseUrl": "http://test/","port": 8080,"store": {"type": "sqlite3",
"databaseUrl": "db.sqlite"}}}}`),
err: ErrConfigNoProfileSelected,
Profile: nil,
profilename: "",
},
}
for _, testCase := range testCases {
profile, profilename, err := NewConfig(testCase.Config)
if err != testCase.err {
t.Errorf("Expected error to be %s, but got %s", testCase.err, err)
continue
}
if profilename != testCase.profilename {
t.Errorf("Expected profilename to be %s, but got %s", testCase.profilename, profilename)
continue
}
if profile != nil && *profile != *testCase.Profile {
t.Errorf("Expected profile to be %+v, but got %+v", testCase.Profile, profile)
continue
}
}
}