Skip to content

Commit

Permalink
whisper: add full filter test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Apr 22, 2015
1 parent 826c196 commit f0105af
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
50 changes: 50 additions & 0 deletions whisper/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,53 @@ func TestFilterTopicsCreation(t *testing.T) {
}
}
}

var filterCompareTests = []struct {
matcher filterer
message filterer
match bool
}{
{ // Wild-card filter matching anything
matcher: filterer{to: "", from: "", matcher: newTopicMatcher()},
message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: true,
},
{ // Filter matching the to field
matcher: filterer{to: "to", from: "", matcher: newTopicMatcher()},
message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: true,
},
{ // Filter rejecting the to field
matcher: filterer{to: "to", from: "", matcher: newTopicMatcher()},
message: filterer{to: "", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: false,
},
{ // Filter matching the from field
matcher: filterer{to: "", from: "from", matcher: newTopicMatcher()},
message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: true,
},
{ // Filter rejecting the from field
matcher: filterer{to: "", from: "from", matcher: newTopicMatcher()},
message: filterer{to: "to", from: "", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: false,
},
{ // Filter matching the topic field
matcher: filterer{to: "", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
match: true,
},
{ // Filter rejecting the topic field
matcher: filterer{to: "", from: "", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
message: filterer{to: "to", from: "from", matcher: newTopicMatcher()},
match: false,
},
}

func TestFilterCompare(t *testing.T) {
for i, tt := range filterCompareTests {
if match := tt.matcher.Compare(tt.message); match != tt.match {
t.Errorf("test %d: match mismatch: have %v, want %v", i, match, tt.match)
}
}
}
3 changes: 1 addition & 2 deletions whisper/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type peer struct {
quit chan struct{}
}

// newPeer creates and initializes a new whisper peer connection, returning either
// the newly constructed link or a failure reason.
// newPeer creates a new whisper peer object, but does not run the handshake itself.
func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *peer {
return &peer{
host: host,
Expand Down

0 comments on commit f0105af

Please sign in to comment.