2013-09-29 06:11:24 +08:00
|
|
|
package peer_protocol
|
2013-09-26 11:43:46 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConstants(t *testing.T) {
|
|
|
|
// check that iota works as expected in the const block
|
|
|
|
if NotInterested != 3 {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 19:51:08 +08:00
|
|
|
func TestBitfieldEncode(t *testing.T) {
|
|
|
|
bm := make(Bitfield, 37)
|
|
|
|
bm[2] = true
|
|
|
|
bm[7] = true
|
|
|
|
bm[32] = true
|
|
|
|
s := string(bm.Encode())
|
|
|
|
const expected = "\x21\x00\x00\x00\x80"
|
|
|
|
if s != expected {
|
|
|
|
t.Fatalf("got %#v, expected %#v", s, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHaveEncode(t *testing.T) {
|
|
|
|
actual := string(Have(42).Encode())
|
|
|
|
expected := "\x04\x00\x00\x00\x2a"
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("expected %#v, got %#v", expected, actual)
|
|
|
|
}
|
|
|
|
}
|