mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 13:32:52 -04:00
some router info tests
This commit is contained in:
@ -11,5 +11,5 @@ func TestTimeFromMiliseconds(t *testing.T) {
|
||||
next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00}
|
||||
go_time := next_day.Time()
|
||||
|
||||
assert.Equal(go_time.Unix(), int64(86400), "Date.Time() did not parse time in milliseconds")
|
||||
assert.Equal(int64(86400), go_time.Unix(), "Date.Time() did not parse time in milliseconds")
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func (router_info RouterInfo) Published() (date Date, err error) {
|
||||
err = errors.New("error parsing date: not enough data")
|
||||
return
|
||||
}
|
||||
copy(remainder[:8], date[:])
|
||||
copy(date[:], remainder[:8])
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,48 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
//"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func buildFullRouterInfo() RouterInfo {
|
||||
// starts with a keys_and_cert
|
||||
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_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...)
|
||||
//RouterAddress(router_address_bytes)
|
||||
return nil
|
||||
router_info_data = append(router_info_data, router_address_bytes...)
|
||||
|
||||
return RouterInfo(router_info_data)
|
||||
}
|
||||
|
||||
func TestPublishedReturnsCorrectDate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
router_info := buildFullRouterInfo()
|
||||
date, err := router_info.Published()
|
||||
assert.Nil(err)
|
||||
assert.Equal(int64(86400), date.Time().Unix(), "RouterInfo.Published() did not return correct date")
|
||||
}
|
||||
|
||||
func TestRouterAddressCountReturnsCorrectCount(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
router_info := buildFullRouterInfo()
|
||||
count, err := router_info.RouterAddressCount()
|
||||
assert.Nil(err)
|
||||
assert.Equal(1, count, "RouterInfo.RouterAddressCount() did not return correct count")
|
||||
}
|
||||
|
||||
func TestRouterAdrressesReturnsAddresses(t *testing.T) {
|
||||
@ -31,7 +54,11 @@ func TestRouterAdrressesReturnsPartialListWithMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPeerSizeIsZero(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
router_info := buildFullRouterInfo()
|
||||
size := router_info.PeerSize()
|
||||
assert.Equal(0, size, "RouterInfo.PeerSize() did not return 0")
|
||||
}
|
||||
|
||||
func TestSignatureIsCorrectSize(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user