integ test verifies messages, confirms content of messages in timeline

This commit is contained in:
Dan Ballard 2018-05-03 15:24:10 -07:00
parent df1976d5a4
commit 12ed7d1618
1 changed files with 18 additions and 4 deletions

View File

@ -60,21 +60,22 @@ func TestCwtchPeerIntegration(t *testing.T) {
groupId, invite := alice.Profile.StartGroup(server_addr)
gci := &protocol.CwtchPeerPacket{}
proto.Unmarshal(invite, gci)
alice.Profile.AddContact(alice.Profile.Onion, alice.Profile.PublicProfile)
alice.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
fmt.Println("Alice joining group...")
alice.JoinServer(server_addr)
// launch bob
bob := peer.NewCwtchPeer("Bob")
bob.Profile.ProcessInvite(gci.GetGroupChatInvite(), server_addr)
bob.Profile.AddContact(bob.Profile.Onion, bob.Profile.PublicProfile)
bob.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
fmt.Println("Bob joining group...")
bob.JoinServer(server_addr)
// Associate peer alice & bob as peers
alice.Profile.AddContact(bob.Profile.Onion, bob.Profile.PublicProfile)
//bob.Profile.AddContact(alice.Profile.Onion, alice.Profile.PublicProfile)
alice.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
bob.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
// Conversation
fmt.Println("Alice> ", aliceLines[0])
alice.SendMessageToGroup(groupId, aliceLines[0])
time.Sleep(time.Second * 2)
@ -101,6 +102,8 @@ func TestCwtchPeerIntegration(t *testing.T) {
// Todo: Alice reconects, gets missed messages (from bob)
// Verify
alicesGroup := alice.Profile.Groups[groupId]
fmt.Printf("Alice TimeLine:\n")
printAndVerifyTimeline(t, alicesGroup.Timeline)
@ -109,5 +112,16 @@ func TestCwtchPeerIntegration(t *testing.T) {
fmt.Printf("Bob TimeLine:\n")
printAndVerifyTimeline(t, bobsGroup.Timeline)
if len(alicesGroup.Timeline.Messages) != 6 {
t.Errorf("Alice's timeline does not have all messages")
return
}
// check message 0,1 and 4,5 for content (2,3 could be out of order)
if alicesGroup.Timeline.Messages[0].Message != aliceLines[0] || alicesGroup.Timeline.Messages[1].Message != bobLines[0] ||
alicesGroup.Timeline.Messages[4].Message != aliceLines[2] || alicesGroup.Timeline.Messages[5].Message != bobLines[2] {
t.Errorf("Some of the messages did not have the expected content!")
}
// Todo: shutdown users and server
}