Browse Source

Moar tests

Evan Huus 12 years ago
parent
commit
aab251251c
2 changed files with 71 additions and 0 deletions
  1. 26 0
      protocol/offset_request_test.go
  2. 45 0
      protocol/produce_request_test.go

+ 26 - 0
protocol/offset_request_test.go

@@ -0,0 +1,26 @@
+package protocol
+
+import "testing"
+
+var (
+	offsetRequestNoBlocks = []byte{
+		0xFF, 0xFF, 0xFF, 0xFF,
+		0x00, 0x00, 0x00, 0x00}
+
+	offsetRequestOneBlock = []byte{
+		0xFF, 0xFF, 0xFF, 0xFF,
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x03, 'f', 'o', 'o',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x00, 0x00, 0x04,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+		0x00, 0x00, 0x00, 0x02}
+)
+
+func TestOffsetRequest(t *testing.T) {
+	request := new(OffsetRequest)
+	testEncodable(t, "no blocks", request, offsetRequestNoBlocks)
+
+	request.AddBlock("foo", 4, 1, 2)
+	testEncodable(t, "one block", request, offsetRequestOneBlock)
+}

+ 45 - 0
protocol/produce_request_test.go

@@ -0,0 +1,45 @@
+package protocol
+
+import "testing"
+
+var (
+	produceRequestEmpty = []byte{
+		0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00}
+
+	produceRequestHeader = []byte{
+		0x01, 0x23,
+		0x00, 0x00, 0x04, 0x44,
+		0x00, 0x00, 0x00, 0x00}
+
+	produceRequestOneMessage = []byte{
+		0x01, 0x23,
+		0x00, 0x00, 0x04, 0x44,
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x05, 't', 'o', 'p', 'i', 'c',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x00, 0x00, 0xAD,
+		0x00, 0x00, 0x00, 0x1C,
+		// messageSet
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x10,
+		// message
+		0x23, 0x96, 0x4a, 0xf7, // CRC
+		0x00,
+		0x00,
+		0xFF, 0xFF, 0xFF, 0xFF,
+		0x00, 0x00, 0x00, 0x02, 0x00, 0xEE}
+)
+
+func TestProduceRequest(t *testing.T) {
+	request := new(ProduceRequest)
+	testEncodable(t, "empty", request, produceRequestEmpty)
+
+	request.ResponseCondition = 0x123
+	request.Timeout = 0x444
+	testEncodable(t, "header", request, produceRequestHeader)
+
+	request.AddMessage("topic", 0xAD, &Message{Codec: COMPRESSION_NONE, Key: nil, Value: []byte{0x00, 0xEE}})
+	testEncodable(t, "one message", request, produceRequestOneMessage)
+}