request_test.go 665 B

123456789101112131415161718192021222324252627282930313233
  1. package protocol
  2. import "testing"
  3. var (
  4. requestSimple = []byte{
  5. 0x00, 0x00, 0x00, 0x16, // msglen
  6. 0x06, 0x66,
  7. 0x00, 0xD2,
  8. 0x00, 0x00, 0x12, 0x34,
  9. 0x00, 0x08, 'm', 'y', 'C', 'l', 'i', 'e', 'n', 't',
  10. 0xDE, 0xAD, 0xBE, 0xEF}
  11. )
  12. type testRequestBody struct {
  13. }
  14. func (s *testRequestBody) key() int16 {
  15. return 0x666
  16. }
  17. func (s *testRequestBody) version() int16 {
  18. return 0xD2
  19. }
  20. func (s *testRequestBody) encode(pe packetEncoder) {
  21. pe.putRaw([]byte{0xDE, 0xAD, 0xBE, 0xEF})
  22. }
  23. func TestRequest(t *testing.T) {
  24. request := request{correlation_id: 0x1234, id: "myClient", body: new(testRequestBody)}
  25. testEncodable(t, "simple", &request, requestSimple)
  26. }