1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
package socket
import (
"bytes"
"testing"
"github.com/digitalocean/go-libvirt/internal/constants"
)
var testHeader = []byte{
0x20, 0x00, 0x80, 0x86, // program
0x00, 0x00, 0x00, 0x01, // version
0x00, 0x00, 0x00, 0x01, // procedure
0x00, 0x00, 0x00, 0x00, // type
0x00, 0x00, 0x00, 0x00, // serial
0x00, 0x00, 0x00, 0x00, // status
}
func TestPktLen(t *testing.T) {
data := []byte{0x00, 0x00, 0x00, 0xa} // uint32:10
r := bytes.NewBuffer(data)
expected := uint32(10)
actual, err := pktlen(r)
if err != nil {
t.Error(err)
}
if expected != actual {
t.Errorf("expected packet length %q, got %q", expected, actual)
}
}
func TestExtractHeader(t *testing.T) {
r := bytes.NewBuffer(testHeader)
h, err := extractHeader(r)
if err != nil {
t.Error(err)
}
if h.Program != constants.Program {
t.Errorf("expected Program %q, got %q", constants.Program, h.Program)
}
if h.Version != constants.ProtocolVersion {
t.Errorf("expected version %q, got %q", constants.ProtocolVersion, h.Version)
}
if h.Procedure != constants.ProcConnectOpen {
t.Errorf("expected procedure %q, got %q", constants.ProcConnectOpen, h.Procedure)
}
if h.Type != Call {
t.Errorf("expected type %q, got %q", Call, h.Type)
}
if h.Status != StatusOK {
t.Errorf("expected status %q, got %q", StatusOK, h.Status)
}
}
|