go-http-peering/test/update_test.go

63 lines
1.1 KiB
Go

package test
import (
"reflect"
"testing"
"time"
peering "forge.cadoles.com/wpetit/go-http-peering"
"forge.cadoles.com/wpetit/go-http-peering/crypto"
)
func TestUpdate(t *testing.T) {
if t.Skipped() {
t.SkipNow()
}
id, pk, client, store := setup(t)
attrs := peering.PeerAttributes{}
if err := client.Advertise(attrs); err != nil {
t.Fatal(err)
}
if err := store.Accept(id); err != nil {
t.Error(err)
}
attrs["Label"] = "Foo Bar"
if err := client.UpdateAttributes(attrs); err != nil {
t.Fatal(err)
}
peer, err := store.Get(id)
if err != nil {
t.Fatal(err)
}
if g, e := peer.ID, id; g != e {
t.Errorf("peer.ID: got '%v', expected '%v'", g, e)
}
if g, e := peer.Attributes, attrs; !reflect.DeepEqual(g, e) {
t.Errorf("peer.Attributes: got '%v', expected '%v'", g, e)
}
var defaultTime time.Time
if peer.LastContact == defaultTime {
t.Error("peer.LastContact should not be time.Time zero value")
}
pem, err := crypto.EncodePublicKeyToPEM(pk.Public())
if err != nil {
t.Fatal(err)
}
if g, e := peer.PublicKey, pem; !reflect.DeepEqual(g, e) {
t.Errorf("peer.PublicKey: got '%v', expected '%v'", g, e)
}
}