Пример #1
0
func TestStreamBinary(t *testing.T) {
	source := []byte("test.data")
	packet := zabbix.Data2Packet(source)
	buf := bytes.NewReader(packet)
	restored, err := zabbix.Stream2Data(buf)
	if err != nil {
		t.Errorf("must be no error: %v", err)
	}
	if !bytes.Equal(restored, source) {
		t.Errorf("invalid data %v <=> %v", restored, source)
	}
}
Пример #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)
	}
}