package test import ( "reflect" "testing" "time" peering "forge.cadoles.com/wpetit/go-http-peering" "forge.cadoles.com/wpetit/go-http-peering/crypto" ) func TestAdvertise(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) } peer, err := store.Get(id) if err != nil { t.Error(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") } if peer.LastAddress == "" { t.Error("peer.LastAddress should not be empty") } 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) } }