diff --git a/lib/common/router_address_test.go b/lib/common/router_address_test.go index 158b9e3..f15296f 100644 --- a/lib/common/router_address_test.go +++ b/lib/common/router_address_test.go @@ -76,12 +76,9 @@ func TestReadRouterAddressReturnsCorrectRemainderWithoutError(t *testing.T) { router_address, remainder, err := ReadRouterAddress(router_address_bytes) assert.Nil(err, "ReadRouterAddress() reported error with valid data:") - if bytes.Compare(remainder, []byte{0x01, 0x02, 0x03}) != 0 { - t.Fatal("incorrect remainder returned on ReadRouterAddress:", remainder) - } + assert.Equal(0, bytes.Compare(remainder, []byte{0x01, 0x02, 0x03})) err, exit := router_address.checkValid() - assert.Nil(err, "checkValid() on address from ReadRouterAddress() reported error with valid data") assert.Equal(exit, false, "checkValid() on address from ReadRouterAddress() indicated to stop parsing valid data") } diff --git a/lib/common/router_info.go b/lib/common/router_info.go index f563537..dd30558 100644 --- a/lib/common/router_info.go +++ b/lib/common/router_info.go @@ -155,7 +155,7 @@ func (router_info RouterInfo) RouterAddresses() (router_addresses []RouterAddres err = errors.New("error parsing router addresses: not enough data") return } - remaining := router_info[9:] + remaining := remainder[9:] var router_address RouterAddress addr_count, cerr := router_info.RouterAddressCount() if cerr != nil { diff --git a/lib/common/router_info_test.go b/lib/common/router_info_test.go index ee62fb2..a8e829b 100644 --- a/lib/common/router_info_test.go +++ b/lib/common/router_info_test.go @@ -1,28 +1,30 @@ package common import ( + "bytes" "github.com/stretchr/testify/assert" "testing" ) -func buildFullRouterInfo() RouterInfo { - router_info_data := make([]byte, 0) - - router_ident_data := make([]byte, 128+256) - router_ident_data = append(router_ident_data, []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}...) - router_info_data = append(router_info_data, router_ident_data...) - - date_data := []byte{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00} - router_info_data = append(router_info_data, date_data...) - - router_info_data = append(router_info_data, 0x01) - +func buildRouterAddress() RouterAddress { router_address_bytes := []byte{0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} str, _ := ToI2PString("foo") mapping, _ := GoMapToMapping(map[string]string{"host": "127.0.0.1", "port": "4567"}) router_address_bytes = append(router_address_bytes, []byte(str)...) router_address_bytes = append(router_address_bytes, mapping...) - router_info_data = append(router_info_data, router_address_bytes...) + + return RouterAddress(router_address_bytes) +} + +func buildFullRouterInfo() RouterInfo { + router_info_data := make([]byte, 0) + router_ident_data := make([]byte, 128+256) + router_ident_data = append(router_ident_data, []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}...) + router_info_data = append(router_info_data, router_ident_data...) + date_data := []byte{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00} + router_info_data = append(router_info_data, date_data...) + router_info_data = append(router_info_data, 0x01) + router_info_data = append(router_info_data, []byte(buildRouterAddress())...) return RouterInfo(router_info_data) } @@ -80,11 +82,20 @@ func TestRouterAddressCountReturnsCorrectErrorWithInvalidData(t *testing.T) { } func TestRouterAddressesReturnsAddresses(t *testing.T) { + assert := assert.New(t) -} - -func TestRouterAddressesReturnsPartialListWithMissing(t *testing.T) { - + router_info := buildFullRouterInfo() + router_addresses, err := router_info.RouterAddresses() + assert.Nil(err) + if assert.Equal(1, len(router_addresses)) { + assert.Equal( + 0, + bytes.Compare( + []byte(buildRouterAddress()), + []byte(router_addresses[0]), + ), + ) + } } func TestPeerSizeIsZero(t *testing.T) {