-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from mailgun/maxim/moremocks
Add mock responses for OffsetManager testing
- Loading branch information
Showing
8 changed files
with
283 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,24 @@ | ||
package sarama | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
) | ||
|
||
var ( | ||
emptyOffsetCommitResponse = []byte{ | ||
0x00, 0x00, 0x00, 0x00} | ||
|
||
normalOffsetCommitResponse = []byte{ | ||
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 len(response.Errors) != 0 { | ||
t.Error("Decoding produced errors where there were none.") | ||
} | ||
testResponse(t, "empty", &response, emptyOffsetCommitResponse) | ||
} | ||
|
||
func TestNormalOffsetCommitResponse(t *testing.T) { | ||
response := OffsetCommitResponse{} | ||
|
||
testDecodable(t, "normal", &response, normalOffsetCommitResponse) | ||
|
||
if len(response.Errors) != 2 { | ||
t.Fatal("Decoding produced wrong number of errors.") | ||
} | ||
|
||
if len(response.Errors["m"]) != 0 { | ||
t.Error("Decoding produced errors for topic 'm' where there were none.") | ||
} | ||
|
||
if len(response.Errors["t"]) != 1 { | ||
t.Fatal("Decoding produced wrong number of errors for topic 't'.") | ||
} | ||
|
||
if response.Errors["t"][0] != ErrNotLeaderForPartition { | ||
t.Error("Decoding produced wrong error for topic 't' partition 0.") | ||
} | ||
|
||
response.AddError("t", 0, ErrNotLeaderForPartition) | ||
response.Errors["m"] = make(map[int32]KError) | ||
// The response encoded form cannot be checked for it varies due to | ||
// unpredictable map traversal order. | ||
testResponse(t, "normal", &response, nil) | ||
} |
Oops, something went wrong.