Ejemplo n.º 1
0
func check(t *testing.T, value, zeroValue bindings.Payload) {
	message, err := bindings.EncodeMessage(bindings.MessageHeader{}, value)
	if err != nil {
		t.Fatalf("error encoding value %v: %v", value, err)
	}
	decodedMessage, err := bindings.ParseMessage(message.Bytes, message.Handles)
	if err != nil {
		t.Fatalf("error decoding message header from bytes %v for tested value %v: %v", message.Bytes, value, err)
	}
	if err = decodedMessage.DecodePayload(zeroValue); err != nil {
		t.Fatalf("error decoding message payload from bytes %v for tested value %v: %v", message.Payload, value, err)
	}
	if !reflect.DeepEqual(value, zeroValue) {
		t.Fatalf("unexpected value after decoding: expected %v, got %v", value, zeroValue)
	}
}
Ejemplo n.º 2
0
func checkMessageEncoding(t *testing.T, header, payload bindings.MessageHeader) {
	var encodedMessage, decodedMessage *bindings.Message
	var err error
	var decodedHeader, decodedPayload bindings.MessageHeader

	if encodedMessage, err = bindings.EncodeMessage(header, &payload); err != nil {
		t.Fatalf("Failed encoding message: %v", err)
	}

	if decodedMessage, err = bindings.ParseMessage(encodedMessage.Bytes, nil); err != nil {
		t.Fatalf("Failed decoding message header: %v", err)
	}
	if decodedHeader = decodedMessage.Header; decodedHeader != header {
		t.Fatalf("Unexpected header decoded: got %v, want %v", decodedHeader, header)
	}
	if err = decodedMessage.DecodePayload(&decodedPayload); err != nil {
		t.Fatalf("Failed decoding message payload: %v", err)
	}
	if decodedPayload != payload {
		t.Fatalf("Unexpected header with request id decoded: got %v, want %v", decodedPayload, payload)
	}
}