From d010dba72e11f0835edf4b996bb7b05e4c234837 Mon Sep 17 00:00:00 2001 From: Joe Zou <yixian.zou@gmail.com> Date: Wed, 8 Jan 2020 15:21:11 +0800 Subject: [PATCH] add test case --- config/condition_router_config_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/config/condition_router_config_test.go b/config/condition_router_config_test.go index a54c951f8..d278752a7 100644 --- a/config/condition_router_config_test.go +++ b/config/condition_router_config_test.go @@ -23,6 +23,8 @@ import ( "github.com/stretchr/testify/assert" ) +const testyml = "testdata/router_config.yml" + func TestString(t *testing.T) { s := "a1=>a2" @@ -41,7 +43,7 @@ func TestString(t *testing.T) { func TestLoadYmlConfig(t *testing.T) { routerConfig = &ConditionRouterConfig{} - e := loadYmlConfig("testdata/router_config.yml", routerConfig) + e := loadYmlConfig(testyml, routerConfig) assert.Nil(t, e) assert.NotNil(t, routerConfig) assert.Equal(t, routerConfig.RawRule, "kkk") @@ -71,3 +73,19 @@ func TestRouterInit(t *testing.T) { assert.Equal(t, routerConfig.Key, "abc") 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") +} -- GitLab