浏览代码

test offset commit response

Evan Huus 12 年之前
父节点
当前提交
3dffa1cbdc
共有 1 个文件被更改,包括 56 次插入0 次删除
  1. 56 0
      protocol/offset_commit_response_test.go

+ 56 - 0
protocol/offset_commit_response_test.go

@@ -0,0 +1,56 @@
+package protocol
+
+import "testing"
+
+var (
+	emptyOffsetCommitResponse = []byte{
+		0xFF, 0xFF,
+		0x00, 0x00, 0x00, 0x00}
+
+	normalOffsetCommitResponse = []byte{
+		0x00, 0x02, 'a', 'z',
+		0x00, 0x00, 0x00, 0x02,
+
+		0x00, 0x01, 'm',
+		0x00, 0x00, 0x00, 0x00,
+
+		0x00, 0x01, 't',
+		0x00, 0x00, 0x00, 0x01,
+		0x00, 0x00, 0x00, 0x00,
+		0x00, 0x06}
+)
+
+func TestEmptyOffsetCommitResponse(t *testing.T) {
+	response := OffsetCommitResponse{}
+
+	testDecodable(t, "empty", &response, emptyOffsetCommitResponse)
+	if response.ClientID != "" {
+		t.Error("Decoding produced client ID where there was none.")
+	}
+	if len(response.Errors) != 0 {
+		t.Error("Decoding produced errors where there were none.")
+	}
+}
+
+func TestNormalOffsetCommitResponse(t *testing.T) {
+	response := OffsetCommitResponse{}
+
+	testDecodable(t, "normal", &response, normalOffsetCommitResponse)
+	if response.ClientID != "az" {
+		t.Error("Decoding produced wrong client ID.")
+	}
+	if len(response.Errors) == 2 {
+		if len(response.Errors["m"]) != 0 {
+			t.Error("Decoding produced errors for topic 'm' where there were none.")
+		}
+		if len(response.Errors["t"]) == 1 {
+			if response.Errors["t"][0] != NOT_LEADER_FOR_PARTITION {
+				t.Error("Decoding produced wrong error for topic 't' partition 0.")
+			}
+		} else {
+			t.Error("Decoding produced wrong number of errors for topic 't'.")
+		}
+	} else {
+		t.Error("Decoding produced wrong number of errors.")
+	}
+}