forked from apolloconfig/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_config_test.go
104 lines (88 loc) · 2.29 KB
/
json_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package agollo
import (
"github.com/livbarn/agollo/test"
"testing"
)
func TestLoadJsonConfig(t *testing.T) {
config, err := loadJsonConfig(appConfigFileName)
t.Log(config)
test.Nil(t, err)
test.NotNil(t, config)
test.Equal(t, "test", config.AppId)
test.Equal(t, "dev", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "localhost:8888", config.Ip)
}
func TestLoadJsonConfigWrongFile(t *testing.T) {
config, err := loadJsonConfig("")
test.NotNil(t, err)
test.Nil(t, config)
test.StartWith(t, "Fail to read config file", err.Error())
}
func TestLoadJsonConfigWrongType(t *testing.T) {
config, err := loadJsonConfig("app_config.go")
test.NotNil(t, err)
test.Nil(t, config)
test.StartWith(t, "Load Json Config fail", err.Error())
}
func TestCreateAppConfigWithJson(t *testing.T) {
jsonStr := `{
"appId": "test",
"cluster": "dev",
"namespaceName": "application",
"ip": "localhost:8888",
"releaseKey": ""
}`
config, err := createAppConfigWithJson(jsonStr)
t.Log(config)
test.Nil(t, err)
test.NotNil(t, config)
test.Equal(t, "test", config.AppId)
test.Equal(t, "dev", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "localhost:8888", config.Ip)
}
//func TestCreateAppConfigWithJsonWrongEnv(t *testing.T) {
// jsonStr:=`{
// "appId": "test",
// "cluster": "joe",
// "namespaceName": "application",
// "ip": "localhost:8888",
// "releaseKey": ""
// }`
// config,err:=createAppConfigWithJson(jsonStr)
// t.Log(config)
// t.Log(err)
//
// test.NotNil(t,err)
// test.Nil(t,config)
// test.StartWith(t,"Env is wrong ,current env:joe",err.Error())
//}
func TestCreateAppConfigWithJsonError(t *testing.T) {
jsonStr := `package agollo
import (
"os"
"strconv"
"time"
"fmt"
"net/url"
)`
config, err := createAppConfigWithJson(jsonStr)
t.Log(err)
test.NotNil(t, err)
test.Nil(t, config)
}
func TestCreateAppConfigWithJsonDefault(t *testing.T) {
jsonStr := `{
"appId": "testDefault",
"ip": "localhost:9999"
}`
config, err := createAppConfigWithJson(jsonStr)
t.Log(err)
test.Nil(t, err)
test.NotNil(t, config)
test.Equal(t, "testDefault", config.AppId)
test.Equal(t, "default", config.Cluster)
test.Equal(t, "application", config.NamespaceName)
test.Equal(t, "localhost:9999", config.Ip)
}