Ejemplo n.º 1
0
func TestCorruptedPacket(t *testing.T) {
	packet := []byte{
		90, 66, 88, 68, // "ZBXD"
		0,                      // CORRUPTED!!
		9, 0, 0, 0, 0, 0, 0, 0, // binary int64(9) == len("test.data")
		116, 101, 115, 116, // "test"
		46,               // "."
		100, 97, 116, 97, // "data"
	}
	restored, err := zabbix.Packet2Data(packet)
	if err == nil {
		t.Errorf("must be error")
	}
	t.Logf("restored: %v", restored)
}
Ejemplo n.º 2
0
func TestPacket(t *testing.T) {
	source := []byte("test.data")
	packet := zabbix.Data2Packet(source)
	compare := []byte{
		90, 66, 88, 68, // "ZBXD"
		1,                      // \x01
		9, 0, 0, 0, 0, 0, 0, 0, // binary int64(9) == len("test.data")
		116, 101, 115, 116, // "test"
		46,               // "."
		100, 97, 116, 97, // "data"
	}
	if !bytes.Equal(packet, compare) {
		t.Errorf("invalid packet %v <=> %v", packet, compare)
	}
	restored, err := zabbix.Packet2Data(packet)
	if err != nil {
		t.Errorf("must be no error: %v", err)
	}
	if !bytes.Equal(restored, source) {
		t.Errorf("invalid data %v <=> %v", restored, source)
	}
}