network_service_matcher/redis/redis_test.go

39 lines
546 B
Go
Raw Permalink Normal View History

2017-12-04 07:27:08 +00:00
package redis
import (
"net"
"testing"
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
const (
ADDR string = "192.168.1.16:26379"
)
func TestRedisMatcher(t *testing.T) {
m := NewMatcher()
conn, _ := net.Dial("tcp", ADDR)
defer conn.Close()
for i := 0; i < m.PacketCount(); i++ {
pack := m.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := cnsm.NewPacket(bytes, n)
if m.Match(nil, i, p) {
t.Log("Redis found.")
return
}
t.Error("Redis not found")
}
}