From ec5d93f5e5714ecf78df334a0f84dc4a98b7395e Mon Sep 17 00:00:00 2001 From: LaurenceLiZhixin <382673304@qq.com> Date: Fri, 26 Mar 2021 20:40:49 +0800 Subject: [PATCH] fix: add test --- .../match_judger/bool_match_judger_test.go | 42 ++++++++++ .../match_judger/double_match_judger_test.go | 55 +++++++++++++ .../double_range_match_judger_test.go | 24 ++++++ .../list_double_match_judger_test.go | 77 +++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 cluster/router/uniform/match_judger/bool_match_judger_test.go create mode 100644 cluster/router/uniform/match_judger/double_match_judger_test.go create mode 100644 cluster/router/uniform/match_judger/double_range_match_judger_test.go create mode 100644 cluster/router/uniform/match_judger/list_double_match_judger_test.go diff --git a/cluster/router/uniform/match_judger/bool_match_judger_test.go b/cluster/router/uniform/match_judger/bool_match_judger_test.go new file mode 100644 index 000000000..d15e1570b --- /dev/null +++ b/cluster/router/uniform/match_judger/bool_match_judger_test.go @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package match_judger + +import ( + "github.com/apache/dubbo-go/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestBoolMatchJudger(t *testing.T) { + assert.True(t, newBoolMatchJudger(&config.BoolMatch{ + Exact: true, + }).Judge(true)) + + assert.True(t, newBoolMatchJudger(&config.BoolMatch{ + Exact: false, + }).Judge(false)) + + assert.False(t, newBoolMatchJudger(&config.BoolMatch{ + Exact: true, + }).Judge(false)) + + assert.False(t, newBoolMatchJudger(&config.BoolMatch{ + Exact: false, + }).Judge(true)) +} diff --git a/cluster/router/uniform/match_judger/double_match_judger_test.go b/cluster/router/uniform/match_judger/double_match_judger_test.go new file mode 100644 index 000000000..59183e9d6 --- /dev/null +++ b/cluster/router/uniform/match_judger/double_match_judger_test.go @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package match_judger + +import ( + "github.com/apache/dubbo-go/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestDoubleMatchJudger(t *testing.T) { + assert.True(t, newDoubleMatchJudger(&config.DoubleMatch{ + Exact: 3.14159, + }).Judge(3.14159)) + + assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{ + Exact: 3.14159, + }).Judge(3.14155927)) + + assert.True(t, newDoubleMatchJudger(&config.DoubleMatch{ + Range: &config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }, + }).Judge(1.3)) + + assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{ + Range: &config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }, + }).Judge(1.9)) + + assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{ + Range: &config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }, + }).Judge(0.9)) +} diff --git a/cluster/router/uniform/match_judger/double_range_match_judger_test.go b/cluster/router/uniform/match_judger/double_range_match_judger_test.go new file mode 100644 index 000000000..23249a24c --- /dev/null +++ b/cluster/router/uniform/match_judger/double_range_match_judger_test.go @@ -0,0 +1,24 @@ +package match_judger + +import ( + "github.com/apache/dubbo-go/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestDoubleRangeMatchJudger(t *testing.T) { + assert.True(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }).Judge(1.3)) + + assert.False(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }).Judge(1.9)) + + assert.False(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{ + Start: 1.0, + End: 1.5, + }).Judge(0.9)) +} diff --git a/cluster/router/uniform/match_judger/list_double_match_judger_test.go b/cluster/router/uniform/match_judger/list_double_match_judger_test.go new file mode 100644 index 000000000..32140fba8 --- /dev/null +++ b/cluster/router/uniform/match_judger/list_double_match_judger_test.go @@ -0,0 +1,77 @@ +package match_judger + +import ( + "github.com/apache/dubbo-go/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestListDoubleMatchJudger_Judge(t *testing.T) { + assert.True(t, newListDoubleMatchJudger(&config.ListDoubleMatch{ + Oneof: []*config.DoubleMatch{ + { + Exact: 3.14, + }, + { + Range: &config.DoubleRangeMatch{ + Start: 1.5, + End: 1.9, + }, + }, + { + Exact: 1.3, + }, + }, + }).Judge(1.3)) + + assert.False(t, newListDoubleMatchJudger(&config.ListDoubleMatch{ + Oneof: []*config.DoubleMatch{ + { + Exact: 3.14, + }, + { + Range: &config.DoubleRangeMatch{ + Start: 1.5, + End: 1.9, + }, + }, + { + Exact: 1.2, + }, + }, + }).Judge(1.3)) + + assert.True(t, newListDoubleMatchJudger(&config.ListDoubleMatch{ + Oneof: []*config.DoubleMatch{ + { + Exact: 3.14, + }, + { + Range: &config.DoubleRangeMatch{ + Start: 1.2, + End: 1.9, + }, + }, + { + Exact: 1.4, + }, + }, + }).Judge(1.3)) + + assert.False(t, newListDoubleMatchJudger(&config.ListDoubleMatch{ + Oneof: []*config.DoubleMatch{ + { + Exact: 3.14, + }, + { + Range: &config.DoubleRangeMatch{ + Start: 1.5, + End: 1.9, + }, + }, + { + Exact: 1.0, + }, + }, + }).Judge(1.3)) +} -- GitLab