package client import ( "crypto/rand" "crypto/rsa" "testing" peeringCrypto "forge.cadoles.com/wpetit/go-http-peering/crypto" peering "forge.cadoles.com/wpetit/go-http-peering" ) func TestClientPeerID(t *testing.T) { serverPK := mustGeneratePrivateKey() peerID := peering.NewPeerID() serverToken, err := peeringCrypto.CreateServerToken(serverPK, "test", peerID) if err != nil { t.Fatal(err) } client := New( WithServerToken(serverToken), ) clientPeerID, err := client.PeerID(&serverPK.PublicKey) if err != nil { t.Fatal(err) } if g, e := clientPeerID, peerID; g != e { t.Errorf("client.PeerID(): got '%v', expected '%v'", g, e) } } func mustGeneratePrivateKey() *rsa.PrivateKey { privateKey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { panic(err) } return privateKey }