test verify

This commit is contained in:
Dan Ballard 2018-05-03 13:03:37 -07:00
parent ec8417b8ec
commit df1976d5a4
1 changed files with 12 additions and 7 deletions

View File

@ -15,7 +15,7 @@ import (
)
const (
server = "kwke2hntvyfqm7dr"//"ylhbhtypevo4ympq"
//server = "kwke2hntvyfqm7dr"//"ylhbhtypevo4ympq"
keyfile = "./private_key"
)
@ -25,16 +25,21 @@ var (
)
func printTimeline(timeline model.Timeline) {
func printAndVerifyTimeline(t *testing.T, timeline model.Timeline) error {
for _, message := range timeline.Messages {
fmt.Printf("%v %v> %s [%t]\n", message.Timestamp, message.PeerID, message.Message, message.Verified)
if !message.Verified {
t.Errorf("Message '%s' from '%s' not verified!", message.Message, message.PeerID)
}
}
return nil
}
func TestCwtchPeerIntegration(t *testing.T) {
// Hide logging "noise"
log.SetOutput(ioutil.Discard)
// TODO: only launch server if not running
// launch app
server := new(cwtchserver.Server)
fmt.Println("starting cwtch server...")
@ -42,7 +47,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
server_key, err := utils.LoadPrivateKeyFromFile(keyfile)
if err != nil {
log.Fatal("Could not load server's key from %v", keyfile)
t.Error("Could not load server's key from %v", keyfile)
}
server_addr, _ := utils.GetOnionAddress(server_key)
@ -66,9 +71,9 @@ func TestCwtchPeerIntegration(t *testing.T) {
fmt.Println("Bob joining group...")
bob.JoinServer(server_addr)
// Associate and peer alice & bob
// Associate peer alice & bob as peers
alice.Profile.AddContact(bob.Profile.Onion, bob.Profile.PublicProfile)
bob.Profile.AddContact(alice.Profile.Onion, alice.Profile.PublicProfile)
//bob.Profile.AddContact(alice.Profile.Onion, alice.Profile.PublicProfile)
fmt.Println("Alice> ", aliceLines[0])
alice.SendMessageToGroup(groupId, aliceLines[0])
@ -98,11 +103,11 @@ func TestCwtchPeerIntegration(t *testing.T) {
alicesGroup := alice.Profile.Groups[groupId]
fmt.Printf("Alice TimeLine:\n")
printTimeline(alicesGroup.Timeline)
printAndVerifyTimeline(t, alicesGroup.Timeline)
bobsGroup := bob.Profile.Groups[groupId]
fmt.Printf("Bob TimeLine:\n")
printTimeline(bobsGroup.Timeline)
printAndVerifyTimeline(t, bobsGroup.Timeline)
// Todo: shutdown users and server
}