Skip to content
Snippets Groups Projects
router_rule_test.go 2.03 KiB
Newer Older
邹毅贤's avatar
邹毅贤 committed
/*
 * 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.
 */

邹毅贤's avatar
邹毅贤 committed
package condition

import (
	"testing"
)
pantianying's avatar
pantianying committed

邹毅贤's avatar
邹毅贤 committed
import (
	"github.com/stretchr/testify/assert"
)

pantianying's avatar
pantianying committed
import (
	"github.com/apache/dubbo-go/common"
)

pantianying's avatar
pantianying committed
func TestGetRule(t *testing.T) {
邹毅贤's avatar
邹毅贤 committed
	testyml := `
scope: application
key: test-provider
邹毅贤's avatar
邹毅贤 committed
runtime: true
force: false
conditions:
  - >
    method!=sayHello =>
  - >
    ip=127.0.0.1
    =>
    1.1.1.1`
pantianying's avatar
pantianying committed
	rule, e := getRule(testyml)
邹毅贤's avatar
邹毅贤 committed

	assert.Nil(t, e)
	assert.NotNil(t, rule)
	assert.Equal(t, 2, len(rule.Conditions))
邹毅贤's avatar
邹毅贤 committed
	assert.Equal(t, "application", rule.Scope)
	assert.True(t, rule.Runtime)
	assert.Equal(t, false, rule.Force)
	assert.Equal(t, testyml, rule.RawRule)
	assert.True(t, rule.Valid)
邹毅贤's avatar
邹毅贤 committed
	assert.Equal(t, false, rule.Enabled)
	assert.Equal(t, false, rule.Dynamic)
	assert.Equal(t, "test-provider", rule.Key)

	testyml = `
key: test-provider
runtime: true
force: false
conditions:
  - >
    method!=sayHello =>`
	rule, e = getRule(testyml)
	assert.Nil(t, e)
	assert.False(t, rule.Valid)

	testyml = `
scope: noApplication
key: test-provider
conditions:
  - >
    method!=sayHello =>`
william feng's avatar
william feng committed
	rule, e = getRule(testyml)
	assert.Nil(t, e)
	assert.False(t, rule.Valid)
邹毅贤's avatar
邹毅贤 committed
}
pantianying's avatar
pantianying committed

func TestIsMatchGlobPattern(t *testing.T) {
	url, _ := common.NewURL("dubbo://localhost:8080/Foo?key=v*e")
haohongfan's avatar
haohongfan committed
	assert.Equal(t, true, isMatchGlobalPattern("$key", "value", url))
pantianying's avatar
pantianying committed
}