File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ package matcher
2
+
3
+ import (
4
+ "github.com/riid/messenger"
5
+ )
6
+
7
+ func Some (matchers ... messenger.Matcher ) messenger.Matcher {
8
+ return MatchFunc (
9
+ func (e messenger.Envelope ) bool {
10
+ for _ , m := range matchers {
11
+ if m .Matches (e ) {
12
+ return true
13
+ }
14
+ }
15
+
16
+ return false
17
+ },
18
+ )
19
+ }
Original file line number Diff line number Diff line change
1
+ package matcher
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+
8
+ "github.com/riid/messenger"
9
+ "github.com/riid/messenger/envelope"
10
+ )
11
+
12
+ func TestSome (t * testing.T ) {
13
+ positive := & matcherStub {true }
14
+ negative := & matcherStub {false }
15
+ e := envelope .FromMessage ([]byte {})
16
+
17
+ type testCase struct {
18
+ matchers []messenger.Matcher
19
+ expected bool
20
+ }
21
+
22
+ suite := map [string ]testCase {
23
+ "no matchers" : {
24
+ expected : false ,
25
+ },
26
+ "all positive matchers" : {
27
+ matchers : []messenger.Matcher {
28
+ positive ,
29
+ positive ,
30
+ },
31
+ expected : true ,
32
+ },
33
+ "all negative matchers" : {
34
+ matchers : []messenger.Matcher {
35
+ negative ,
36
+ negative ,
37
+ },
38
+ expected : false ,
39
+ },
40
+ "one negative matcher" : {
41
+ matchers : []messenger.Matcher {
42
+ positive ,
43
+ negative ,
44
+ positive ,
45
+ },
46
+ expected : true ,
47
+ },
48
+ }
49
+
50
+ for name , tc := range suite {
51
+ tc := tc
52
+ t .Run (
53
+ name , func (t * testing.T ) {
54
+ t .Parallel ()
55
+
56
+ m := Some (tc .matchers ... )
57
+ assert .Equal (t , tc .expected , m .Matches (e ))
58
+ },
59
+ )
60
+ }
61
+ }
You can’t perform that action at this time.
0 commit comments