package postgresql

import (
	"git.loafle.net/overflow/overflow_probe/discovery/core/scan/service/matcher/packet"
	"net"
	"testing"
)

func TestPG(t *testing.T) {
	m := NewPostgreSQLMatcher()

	conn, err := net.Dial("tcp", "192.168.1.88:5432")
	if err != nil {
		t.Error(err)
		return
	}
	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 := packet.NewPacket(bytes, n)

		if m.Match(i, p, nil) {
			t.Log("PostgreSQL found")
			return
		}

		t.Error("PostgreSQL not found")
	}
}
