Skip to content

Commit dd765f6

Browse files
committed
add tests for exact match
1 parent 9211ad4 commit dd765f6

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

message_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ func TestMatch(t *testing.T) {
118118
}
119119
}
120120

121+
func TestMatchExactly(t *testing.T) {
122+
for i, testcase := range []struct {
123+
Msg Message
124+
Addr string
125+
ShouldMatch bool
126+
}{
127+
{
128+
Msg: Message{Address: "/foo/bar"},
129+
Addr: "/foo/bar",
130+
ShouldMatch: true,
131+
},
132+
} {
133+
var (
134+
msg = testcase.Msg
135+
addr = testcase.Addr
136+
)
137+
match, err := msg.Match(addr, true)
138+
139+
if err != nil {
140+
t.Fatal(err)
141+
}
142+
if testcase.ShouldMatch {
143+
if !match {
144+
t.Fatalf("(test case %d) expected %#v to match address %s", i, msg, addr)
145+
}
146+
} else {
147+
if match {
148+
t.Fatalf("(test case %d) expected %#v to not match address %s", i, msg, addr)
149+
}
150+
}
151+
}
152+
}
153+
121154
func TestGetRegex(t *testing.T) {
122155
if _, err := GetRegex(`[`); err == nil {
123156
t.Fatalf("expected error, got nil")

udp_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ func testUDPServer(t *testing.T, dispatcher Dispatcher) (*UDPConn, *UDPConn, cha
119119
}
120120

121121
func TestUDPConnSend_OK(t *testing.T) {
122-
_, conn, errChan := testUDPServer(t, nil)
122+
server, conn, errChan := testUDPServer(t, nil)
123+
server.SetExactMatch(true)
123124
if err := conn.Send(Message{Address: "/server/close"}); err != nil {
124125
t.Fatal(err)
125126
}
@@ -128,6 +129,9 @@ func TestUDPConnSend_OK(t *testing.T) {
128129
}
129130
}
130131

132+
func TestUDPConnSend_ExactMatch(t *testing.T) {
133+
}
134+
131135
// errUDPConn is an implementation of the udpConn interface that returns errors from all it's methods.
132136
type errUDPConn struct {
133137
udpConn

unix_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestUnixSend(t *testing.T) {
3636
return nil
3737
}),
3838
})
39+
server.SetExactMatch(true)
3940
addr, err := net.ResolveUnixAddr("unixgram", server.LocalAddr().String())
4041
if err != nil {
4142
t.Fatal(err)

0 commit comments

Comments
 (0)