Browse Source

Moar tests

Evan Huus 12 years ago
parent
commit
81a1f790dd

+ 4 - 4
protocol/metadata_request_test.go

@@ -8,13 +8,13 @@ var (
 
 	metadataRequestOneTopic = []byte{
 		0x00, 0x00, 0x00, 0x01,
-		0x00, 0x06,  't',  'o',  'p',  'i',  'c',  '1'}
+		0x00, 0x06, 't', 'o', 'p', 'i', 'c', '1'}
 
 	metadataRequestThreeTopics = []byte{
 		0x00, 0x00, 0x00, 0x03,
-		0x00, 0x03,  'f',  'o',  'o',
-		0x00, 0x03,  'b',  'a',  'r',
-		0x00, 0x03,  'b',  'a',  'z'}
+		0x00, 0x03, 'f', 'o', 'o',
+		0x00, 0x03, 'b', 'a', 'r',
+		0x00, 0x03, 'b', 'a', 'z'}
 )
 
 func TestMetadataRequest(t *testing.T) {

+ 33 - 0
protocol/offset_commit_request_test.go

@@ -0,0 +1,33 @@
+package protocol
+
+import "testing"
+
+var (
+	offsetCommitRequestNoGroupNoBlocks = []byte{
+		0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00}
+
+	offsetCommitRequestNoBlocks = []byte{
+		0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
+		0x00, 0x00, 0x00, 0x00}
+
+	offsetCommitRequestOneBlock = []byte{
+		0x00, 0x06, 'f', 'o', 'o', 'b', 'a', 'r',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x05, 't', 'o', 'p', 'i', 'c',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x00, 0x52, 0x21,
+		0x00, 0x00, 0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF,
+		0x00, 0x08, 'm', 'e', 't', 'a', 'd', 'a', 't', 'a'}
+)
+
+func TestOffsetCommitRequest(t *testing.T) {
+	request := new(OffsetCommitRequest)
+	testEncodable(t, "no group, no blocks", request, offsetCommitRequestNoGroupNoBlocks)
+
+	request.ConsumerGroup = "foobar"
+	testEncodable(t, "no blocks", request, offsetCommitRequestNoBlocks)
+
+	request.AddBlock("topic", 0x5221, 0xDEADBEEF, "metadata")
+	testEncodable(t, "one block", request, offsetCommitRequestOneBlock)
+}

+ 31 - 0
protocol/offset_fetch_request_test.go

@@ -0,0 +1,31 @@
+package protocol
+
+import "testing"
+
+var (
+	offsetFetchRequestNoGroupNoPartitions = []byte{
+		0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00}
+
+	offsetFetchRequestNoPartitions = []byte{
+		0x00, 0x04, 'b', 'l', 'a', 'h',
+		0x00, 0x00, 0x00, 0x00}
+
+	offsetFetchRequestOnePartition = []byte{
+		0x00, 0x04, 'b', 'l', 'a', 'h',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x0D, 't', 'o', 'p', 'i', 'c', 'T', 'h', 'e', 'F', 'i', 'r', 's', 't',
+		0x00, 0x00, 0x00, 0x01,
+		0x4F, 0x4F, 0x4F, 0x4F}
+)
+
+func TestOffsetFetchRequest(t *testing.T) {
+	request := new(OffsetFetchRequest)
+	testEncodable(t, "no group, no partitions", request, offsetFetchRequestNoGroupNoPartitions)
+
+	request.ConsumerGroup = "blah"
+	testEncodable(t, "no partitions", request, offsetFetchRequestNoPartitions)
+
+	request.AddPartition("topicTheFirst", 0x4F4F4F4F)
+	testEncodable(t, "one partition", request, offsetFetchRequestOnePartition)
+}