Skip to content
Snippets Groups Projects
Commit d010dba7 authored by 邹毅贤's avatar 邹毅贤
Browse files

add test case

parent fae008aa
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ import ( ...@@ -23,6 +23,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
const testyml = "testdata/router_config.yml"
func TestString(t *testing.T) { func TestString(t *testing.T) {
s := "a1=>a2" s := "a1=>a2"
...@@ -41,7 +43,7 @@ func TestString(t *testing.T) { ...@@ -41,7 +43,7 @@ func TestString(t *testing.T) {
func TestLoadYmlConfig(t *testing.T) { func TestLoadYmlConfig(t *testing.T) {
routerConfig = &ConditionRouterConfig{} routerConfig = &ConditionRouterConfig{}
e := loadYmlConfig("testdata/router_config.yml", routerConfig) e := loadYmlConfig(testyml, routerConfig)
assert.Nil(t, e) assert.Nil(t, e)
assert.NotNil(t, routerConfig) assert.NotNil(t, routerConfig)
assert.Equal(t, routerConfig.RawRule, "kkk") assert.Equal(t, routerConfig.RawRule, "kkk")
...@@ -71,3 +73,19 @@ func TestRouterInit(t *testing.T) { ...@@ -71,3 +73,19 @@ func TestRouterInit(t *testing.T) {
assert.Equal(t, routerConfig.Key, "abc") assert.Equal(t, routerConfig.Key, "abc")
assert.Equal(t, len(routerConfig.Conditions), 2) assert.Equal(t, len(routerConfig.Conditions), 2)
} }
func TestParseCondition(t *testing.T) {
s := make([]string, 2)
s = append(s, "a => b")
s = append(s, "c => d")
condition := parseCondition(s)
assert.Equal(t, "a & c => b & d", condition)
}
func TestInitRouterUrl(t *testing.T) {
routerConfig = &ConditionRouterConfig{}
loadYmlConfig(testyml, routerConfig)
url := initRouterUrl()
assert.Equal(t, url.Protocol, "route")
assert.Equal(t, url.Ip, "0.0.0.0")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment