added test cases

This commit is contained in:
Trung Nguyen 2018-10-11 15:05:37 -04:00
parent b9ee7c9719
commit cbba21e9fc
No known key found for this signature in database
GPG Key ID: 4636434ED9505EB7
1 changed files with 37 additions and 0 deletions

View File

@ -177,3 +177,40 @@ func TestMessageEncodeDecode(t *testing.T) {
testSubject(t)
testSubjectWithSignature(t)
}
func TestIsIstanbulPayload_whenTypical(t *testing.T) {
msg := &message{
Code: uint64(1),
Msg: []byte{0, 1},
}
payload, err := Encode(msg)
if err != nil {
t.Fatalf("unable to encode message %v", err)
}
ok := IsIstanbulPayload(payload)
if !ok {
t.Error("expected true but got false")
}
}
func TestIsIstanbulPayload_whenPayloadIsEmpty(t *testing.T) {
var payload []byte
ok := IsIstanbulPayload(payload)
if ok {
t.Error("expected false but got true")
}
}
func TestIsIstanbulPayload_whenInvalidPayload(t *testing.T) {
payload := []byte{0, 1}
ok := IsIstanbulPayload(payload)
if ok {
t.Error("expected false but got true")
}
}