2016-02-05 02:23:11 -08:00
|
|
|
package common
|
2016-02-13 21:00:29 -08:00
|
|
|
|
|
|
|
import (
|
2016-06-19 14:26:03 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-02-13 21:00:29 -08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func buildFullRouterInfo() RouterInfo {
|
2016-06-19 14:26:03 -07:00
|
|
|
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)
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
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...)
|
2016-06-19 14:26:03 -07:00
|
|
|
router_info_data = append(router_info_data, router_address_bytes...)
|
|
|
|
|
|
|
|
return RouterInfo(router_info_data)
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func TestPublishedReturnsCorrectDate(t *testing.T) {
|
2016-06-19 14:26:03 -07:00
|
|
|
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")
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func TestRouterAddressCountReturnsCorrectCount(t *testing.T) {
|
2016-06-19 14:26:03 -07:00
|
|
|
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")
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func TestRouterAdrressesReturnsAddresses(t *testing.T) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouterAdrressesReturnsPartialListWithMissing(t *testing.T) {
|
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func TestPeerSizeIsZero(t *testing.T) {
|
2016-06-19 14:26:03 -07:00
|
|
|
assert := assert.New(t)
|
2016-02-16 01:04:40 -08:00
|
|
|
|
2016-06-19 14:26:03 -07:00
|
|
|
router_info := buildFullRouterInfo()
|
|
|
|
size := router_info.PeerSize()
|
|
|
|
assert.Equal(0, size, "RouterInfo.PeerSize() did not return 0")
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2016-02-16 01:04:40 -08:00
|
|
|
func TestSignatureIsCorrectSize(t *testing.T) {
|
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|