|
|
@ -776,6 +776,7 @@ func TestWatchers(t *testing.T) { |
|
|
|
func TestVariableTopics(t *testing.T) { |
|
|
|
func TestVariableTopics(t *testing.T) { |
|
|
|
InitSingleTest() |
|
|
|
InitSingleTest() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastTopicByte = 3 |
|
|
|
var match bool |
|
|
|
var match bool |
|
|
|
params, err := generateMessageParams() |
|
|
|
params, err := generateMessageParams() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -796,19 +797,52 @@ func TestVariableTopics(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 4; i++ { |
|
|
|
for i := 0; i < 4; i++ { |
|
|
|
arr := make([]byte, i+1, 4) |
|
|
|
env.Topic = BytesToTopic(f.Topics[i]) |
|
|
|
copy(arr, env.Topic[:i+1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f.Topics[4] = arr |
|
|
|
|
|
|
|
match = f.MatchEnvelope(env) |
|
|
|
match = f.MatchEnvelope(env) |
|
|
|
if !match { |
|
|
|
if !match { |
|
|
|
t.Fatalf("failed MatchEnvelope symmetric with seed %d, step %d.", seed, i) |
|
|
|
t.Fatalf("failed MatchEnvelope symmetric with seed %d, step %d.", seed, i) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f.Topics[4][i]++ |
|
|
|
f.Topics[i][lastTopicByte]++ |
|
|
|
match = f.MatchEnvelope(env) |
|
|
|
match = f.MatchEnvelope(env) |
|
|
|
if match { |
|
|
|
if match { |
|
|
|
t.Fatalf("MatchEnvelope symmetric with seed %d, step %d: false positive.", seed, i) |
|
|
|
t.Fatalf("MatchEnvelope symmetric with seed %d, step %d: false positive.", seed, i) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMatchSingleTopic_ReturnTrue(t *testing.T) { |
|
|
|
|
|
|
|
bt := []byte("test") |
|
|
|
|
|
|
|
topic := BytesToTopic(bt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !matchSingleTopic(topic, bt) { |
|
|
|
|
|
|
|
t.FailNow() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) { |
|
|
|
|
|
|
|
bt := []byte("test with tail") |
|
|
|
|
|
|
|
topic := BytesToTopic([]byte("test")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !matchSingleTopic(topic, bt) { |
|
|
|
|
|
|
|
t.FailNow() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) { |
|
|
|
|
|
|
|
bt := []byte("tes") |
|
|
|
|
|
|
|
topic := BytesToTopic(bt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if matchSingleTopic(topic, bt) { |
|
|
|
|
|
|
|
t.FailNow() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) { |
|
|
|
|
|
|
|
bt := []byte("test") |
|
|
|
|
|
|
|
topic := BytesToTopic([]byte("not_equal")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if matchSingleTopic(topic, bt) { |
|
|
|
|
|
|
|
t.FailNow() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|