Browse Source

fix tests

Evan Huus 12 years ago
parent
commit
6d220ddebd

+ 4 - 3
protocol/metadata_response_test.go

@@ -1,6 +1,7 @@
 package protocol
 package protocol
 
 
 import "testing"
 import "testing"
+import "sarama/types"
 
 
 var (
 var (
 	emptyMetadataResponse = []byte{
 	emptyMetadataResponse = []byte{
@@ -89,14 +90,14 @@ func TestMetadataResponseWithTopics(t *testing.T) {
 		t.Error("Decoding produced", len(response.Brokers), "brokers where there were none!")
 		t.Error("Decoding produced", len(response.Brokers), "brokers where there were none!")
 	}
 	}
 	if len(response.Topics) == 2 {
 	if len(response.Topics) == 2 {
-		if response.Topics[0].Err != NO_ERROR {
+		if response.Topics[0].Err != types.NO_ERROR {
 			t.Error("Decoding produced invalid topic 0 error.")
 			t.Error("Decoding produced invalid topic 0 error.")
 		}
 		}
 		if response.Topics[0].Name != "foo" {
 		if response.Topics[0].Name != "foo" {
 			t.Error("Decoding produced invalid topic 0 name.")
 			t.Error("Decoding produced invalid topic 0 name.")
 		}
 		}
 		if len(response.Topics[0].Partitions) == 1 {
 		if len(response.Topics[0].Partitions) == 1 {
-			if response.Topics[0].Partitions[0].Err != INVALID_MESSAGE_SIZE {
+			if response.Topics[0].Partitions[0].Err != types.INVALID_MESSAGE_SIZE {
 				t.Error("Decoding produced invalid topic 0 partition 0 error.")
 				t.Error("Decoding produced invalid topic 0 partition 0 error.")
 			}
 			}
 			if response.Topics[0].Partitions[0].Id != 0x01 {
 			if response.Topics[0].Partitions[0].Id != 0x01 {
@@ -120,7 +121,7 @@ func TestMetadataResponseWithTopics(t *testing.T) {
 		} else {
 		} else {
 			t.Error("Decoding produced invalid partition count for topic 0.")
 			t.Error("Decoding produced invalid partition count for topic 0.")
 		}
 		}
-		if response.Topics[1].Err != NO_ERROR {
+		if response.Topics[1].Err != types.NO_ERROR {
 			t.Error("Decoding produced invalid topic 1 error.")
 			t.Error("Decoding produced invalid topic 1 error.")
 		}
 		}
 		if response.Topics[1].Name != "bar" {
 		if response.Topics[1].Name != "bar" {

+ 2 - 1
protocol/offset_commit_response_test.go

@@ -1,6 +1,7 @@
 package protocol
 package protocol
 
 
 import "testing"
 import "testing"
+import "sarama/types"
 
 
 var (
 var (
 	emptyOffsetCommitResponse = []byte{
 	emptyOffsetCommitResponse = []byte{
@@ -44,7 +45,7 @@ func TestNormalOffsetCommitResponse(t *testing.T) {
 			t.Error("Decoding produced errors for topic 'm' where there were none.")
 			t.Error("Decoding produced errors for topic 'm' where there were none.")
 		}
 		}
 		if len(response.Errors["t"]) == 1 {
 		if len(response.Errors["t"]) == 1 {
-			if response.Errors["t"][0] != NOT_LEADER_FOR_PARTITION {
+			if response.Errors["t"][0] != types.NOT_LEADER_FOR_PARTITION {
 				t.Error("Decoding produced wrong error for topic 't' partition 0.")
 				t.Error("Decoding produced wrong error for topic 't' partition 0.")
 			}
 			}
 		} else {
 		} else {

+ 2 - 1
protocol/offset_response_test.go

@@ -1,6 +1,7 @@
 package protocol
 package protocol
 
 
 import "testing"
 import "testing"
+import "sarama/types"
 
 
 var (
 var (
 	emptyOffsetResponse = []byte{
 	emptyOffsetResponse = []byte{
@@ -40,7 +41,7 @@ func TestNormalOffsetResponse(t *testing.T) {
 		}
 		}
 
 
 		if len(response.Blocks["z"]) == 1 {
 		if len(response.Blocks["z"]) == 1 {
-			if response.Blocks["z"][2].Err != NO_ERROR {
+			if response.Blocks["z"][2].Err != types.NO_ERROR {
 				t.Error("Decoding produced invalid error for topic z partition 2.")
 				t.Error("Decoding produced invalid error for topic z partition 2.")
 			}
 			}
 			if len(response.Blocks["z"][2].Offsets) == 2 {
 			if len(response.Blocks["z"][2].Offsets) == 2 {

+ 2 - 1
protocol/produce_request_test.go

@@ -1,6 +1,7 @@
 package protocol
 package protocol
 
 
 import "testing"
 import "testing"
+import "sarama/types"
 
 
 var (
 var (
 	produceRequestEmpty = []byte{
 	produceRequestEmpty = []byte{
@@ -40,6 +41,6 @@ func TestProduceRequest(t *testing.T) {
 	request.Timeout = 0x444
 	request.Timeout = 0x444
 	testEncodable(t, "header", request, produceRequestHeader)
 	testEncodable(t, "header", request, produceRequestHeader)
 
 
-	request.AddMessage("topic", 0xAD, &Message{Codec: COMPRESSION_NONE, Key: nil, Value: []byte{0x00, 0xEE}})
+	request.AddMessage("topic", 0xAD, &Message{Codec: types.COMPRESSION_NONE, Key: nil, Value: []byte{0x00, 0xEE}})
 	testEncodable(t, "one message", request, produceRequestOneMessage)
 	testEncodable(t, "one message", request, produceRequestOneMessage)
 }
 }

+ 3 - 2
protocol/produce_response_test.go

@@ -1,6 +1,7 @@
 package protocol
 package protocol
 
 
 import "testing"
 import "testing"
+import "sarama/types"
 
 
 var (
 var (
 	produceResponseNoBlocks = []byte{
 	produceResponseNoBlocks = []byte{
@@ -46,7 +47,7 @@ func TestProduceResponse(t *testing.T) {
 	if block == nil {
 	if block == nil {
 		t.Error("Decoding did not produce a block for bar/1")
 		t.Error("Decoding did not produce a block for bar/1")
 	} else {
 	} else {
-		if block.Err != NO_ERROR {
+		if block.Err != types.NO_ERROR {
 			t.Error("Decoding failed for bar/1/Err, got:", int16(block.Err))
 			t.Error("Decoding failed for bar/1/Err, got:", int16(block.Err))
 		}
 		}
 		if block.Offset != 0xFF {
 		if block.Offset != 0xFF {
@@ -57,7 +58,7 @@ func TestProduceResponse(t *testing.T) {
 	if block == nil {
 	if block == nil {
 		t.Error("Decoding did not produce a block for bar/2")
 		t.Error("Decoding did not produce a block for bar/2")
 	} else {
 	} else {
-		if block.Err != INVALID_MESSAGE {
+		if block.Err != types.INVALID_MESSAGE {
 			t.Error("Decoding failed for bar/2/Err, got:", int16(block.Err))
 			t.Error("Decoding failed for bar/2/Err, got:", int16(block.Err))
 		}
 		}
 		if block.Offset != 0 {
 		if block.Offset != 0 {

+ 9 - 8
protocol/request_test.go

@@ -1,5 +1,6 @@
 package protocol
 package protocol
 
 
+import enc "sarama/encoding"
 import (
 import (
 	"bytes"
 	"bytes"
 	"testing"
 	"testing"
@@ -7,12 +8,12 @@ import (
 
 
 var (
 var (
 	requestSimple = []byte{
 	requestSimple = []byte{
-		0x00, 0x00, 0x00, 0x16, // msglen
+		0x00, 0x00, 0x00, 0x17, // msglen
 		0x06, 0x66,
 		0x06, 0x66,
 		0x00, 0xD2,
 		0x00, 0xD2,
 		0x00, 0x00, 0x12, 0x34,
 		0x00, 0x00, 0x12, 0x34,
 		0x00, 0x08, 'm', 'y', 'C', 'l', 'i', 'e', 'n', 't',
 		0x00, 0x08, 'm', 'y', 'C', 'l', 'i', 'e', 'n', 't',
-		0xDE, 0xAD, 0xBE, 0xEF}
+		0x00, 0x03, 'a', 'b', 'c'}
 )
 )
 
 
 type testRequestBody struct {
 type testRequestBody struct {
@@ -26,8 +27,8 @@ func (s *testRequestBody) version() int16 {
 	return 0xD2
 	return 0xD2
 }
 }
 
 
-func (s *testRequestBody) encode(pe packetEncoder) {
-	pe.putRaw([]byte{0xDE, 0xAD, 0xBE, 0xEF})
+func (s *testRequestBody) Encode(pe enc.PacketEncoder) error {
+	return pe.PutString("abc")
 }
 }
 
 
 func TestRequest(t *testing.T) {
 func TestRequest(t *testing.T) {
@@ -38,8 +39,8 @@ func TestRequest(t *testing.T) {
 // not specific to request tests, just helper functions for testing structures that
 // not specific to request tests, just helper functions for testing structures that
 // implement the encoder or decoder interfaces that needed somewhere to live
 // implement the encoder or decoder interfaces that needed somewhere to live
 
 
-func testEncodable(t *testing.T, name string, in encoder, expect []byte) {
-	packet, err := encode(in)
+func testEncodable(t *testing.T, name string, in enc.Encoder, expect []byte) {
+	packet, err := enc.Encode(in)
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
 	} else if !bytes.Equal(packet, expect) {
 	} else if !bytes.Equal(packet, expect) {
@@ -47,8 +48,8 @@ func testEncodable(t *testing.T, name string, in encoder, expect []byte) {
 	}
 	}
 }
 }
 
 
-func testDecodable(t *testing.T, name string, out decoder, in []byte) {
-	err := decode(in, out)
+func testDecodable(t *testing.T, name string, out enc.Decoder, in []byte) {
+	err := enc.Decode(in, out)
 	if err != nil {
 	if err != nil {
 		t.Error("Decoding", name, "failed:", err)
 		t.Error("Decoding", name, "failed:", err)
 	}
 	}