mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-05 14:13:30 -04:00
router info test and bug fixes
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user