-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmatcher_test.go
45 lines (36 loc) · 1.12 KB
/
matcher_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package pubsub_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/pubsub/v2"
)
type MatcherSuite struct{}
var (
_ = gc.Suite(&MatcherSuite{})
first = "first"
firstdot = "first.next"
second = "second"
secondfirst = "second.first.next"
space = "a topic"
)
func (*MatcherSuite) TestMatchAll(c *gc.C) {
matcher := pubsub.MatchAll
c.Check(matcher(first), jc.IsTrue)
c.Check(matcher(firstdot), jc.IsTrue)
c.Check(matcher(second), jc.IsTrue)
c.Check(matcher(secondfirst), jc.IsTrue)
c.Check(matcher(space), jc.IsTrue)
}
func (*MatcherSuite) TestMatchRegexpPanicsOnInvalid(c *gc.C) {
c.Check(func() { pubsub.MatchRegexp("*") }, gc.PanicMatches, "regexp: Compile.*: error parsing regexp: .*")
}
func (*MatcherSuite) TestMatchRegexp(c *gc.C) {
matcher := pubsub.MatchRegexp("first.*")
c.Check(matcher(first), jc.IsTrue)
c.Check(matcher(firstdot), jc.IsTrue)
c.Check(matcher(second), jc.IsFalse)
c.Check(matcher(secondfirst), jc.IsTrue)
c.Check(matcher(space), jc.IsFalse)
}