コード例 #1
0
func TestWalkDummy(t *testing.T) {
	matchT := NewStaticMatcher("true")
	matchF := NewStaticMatcher("false")

	trie0 := DummyTrie("test")
	trie1 := DummyTrie("test")
	if trie0 == nil || trie1 == nil {
		t.Errorf("cannot create dummy trie")
	}

	pool0 := backend.DummyPool("test")
	pool1 := backend.DummyPool("test")
	if pool0 == nil || pool1 == nil {
		t.Errorf("cannot create dummy pool")
	}

	rule0 := NewRule("rule0", matchT, trie0, pool0)
	rule0.Dummy = true

	rule1 := NewRule("rule1", matchF, trie1, pool1)

	rules := []*Rule{rule0, rule1}
	trie := NewTrie("test", rules)

	req, _ := http.NewRequest("GET", "/", nil)
	pool, next := trie.Walk(req)
	if pool != nil || next != nil {
		t.Errorf("should not match dummy")
	}
}
コード例 #2
0
func (c *Config) ConstructRule(rule Rule) *routing.Rule {
	if rule.Next == "" && rule.Pool == "" {
		logger.Errorf("[rule %s] no pool or trie", rule.Name)
		return routing.DummyRule(rule.Name)
	}

	var next *routing.Trie
	if rule.Next != "" {
		next = c.Tries[rule.Next]
		if next == nil {
			logger.Errorf("[rule %s] trie %s absent", rule.Name, rule.Next)
			next = routing.DummyTrie(rule.Next)
		}
	}

	var pool *backend.Pool
	if rule.Pool != "" {
		pool = c.Pools[rule.Pool]
		if pool == nil {
			logger.Errorf("[rule %s] trie %s absent", rule.Name, rule.Pool)
			pool = backend.DummyPool(rule.Pool)
		}
	}

	matcher, err := c.MatcherFactory.Make(rule.Type, rule.Value)
	if err != nil {
		logger.Errorf("[rule %s] setting matcher false", rule.Name)
		matcher = routing.NewStaticMatcher("false")
	}

	return routing.NewRule(rule.Name, matcher, next, pool)
}