forked from cwtch.im/cwtch
expand integ test:
- run own server; delete pk from repo - test now can use preexisting server if online (checks) - alice & bob users - chat - pretty print results - verify messages and content TODO: disconnect and reconnect to confirm offline delivery TODO: use preexisting test server
This commit is contained in:
parent
8e7cd9c04b
commit
af004e4641
|
@ -93,25 +93,48 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
}
|
||||
|
||||
// launch alice
|
||||
fmt.Println("Creating Alice...")
|
||||
alice := peer.NewCwtchPeer("Alice")
|
||||
groupId, invite := alice.Profile.StartGroup(serverAddr)
|
||||
alice.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
|
||||
fmt.Println("Alice created:", alice.Profile.Onion)
|
||||
|
||||
fmt.Println("Starting group on ", serverAddr, "...")
|
||||
groupId, invite, err := alice.Profile.StartGroup(serverAddr)
|
||||
fmt.Printf("Started group: %v!\n", groupId)
|
||||
if err != nil {
|
||||
t.Error("Failed to start group: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
gci := &protocol.CwtchPeerPacket{}
|
||||
proto.Unmarshal(invite, gci)
|
||||
alice.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
|
||||
fmt.Println("Alice joining group...")
|
||||
|
||||
|
||||
fmt.Println("Alice joining server/group...")
|
||||
alice.JoinServer(serverAddr)
|
||||
|
||||
// launch bob
|
||||
fmt.Println("Creating Bob...")
|
||||
bob := peer.NewCwtchPeer("Bob")
|
||||
bob.Profile.ProcessInvite(gci.GetGroupChatInvite(), serverAddr)
|
||||
bob.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
|
||||
fmt.Println("Bob joining group...")
|
||||
bob.JoinServer(serverAddr)
|
||||
fmt.Println("Bob created:", bob.Profile.Onion)
|
||||
|
||||
// Associate peer alice & bob as peers
|
||||
fmt.Println("Peering Alice and Bob...")
|
||||
alice.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
|
||||
bob.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
|
||||
|
||||
// TODO: have alice actually protocolly send the invite
|
||||
fmt.Printf("Bob processing invite to group %v\n", gci.GetGroupChatInvite().GroupName)
|
||||
bob.Profile.ProcessInvite(gci.GetGroupChatInvite(), alice.Profile.Onion)
|
||||
|
||||
fmt.Println("Bob joining server/group...")
|
||||
bob.JoinServer(serverAddr)
|
||||
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
|
||||
fmt.Println("Starting conversation in group...")
|
||||
// Conversation
|
||||
fmt.Println("Alice> ", aliceLines[0])
|
||||
alice.SendMessageToGroup(groupId, aliceLines[0])
|
||||
|
@ -121,11 +144,12 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
bob.SendMessageToGroup(groupId, bobLines[0])
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
// "instant" - could be either order?
|
||||
fmt.Println("Alice> ", aliceLines[1])
|
||||
alice.SendMessageToGroup(groupId, aliceLines[1])
|
||||
fmt.Println("Bob> ", bobLines[1])
|
||||
bob.SendMessageToGroup(groupId, bobLines[1])
|
||||
time.Sleep(time.Second * 2)
|
||||
time.Sleep(time.Second * 3)
|
||||
|
||||
fmt.Println("Alice> ", aliceLines[2])
|
||||
alice.SendMessageToGroup(groupId, aliceLines[2])
|
||||
|
@ -142,15 +166,32 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
// Verify
|
||||
|
||||
// final syncing time...
|
||||
time.Sleep(time.Second * 2)
|
||||
time.Sleep(time.Second * 4)
|
||||
|
||||
alicesGroup := alice.Profile.GetGroupByGroupID(groupId)
|
||||
fmt.Printf("alice Groups:\n")
|
||||
for k := range alice.Profile.Groups {
|
||||
fmt.Println(" " + k)
|
||||
}
|
||||
if alicesGroup == nil {
|
||||
t.Error("aliceGroup == nil")
|
||||
return
|
||||
}
|
||||
|
||||
alicesGroup := alice.Profile.Groups[groupId]
|
||||
fmt.Printf("Alice TimeLine:\n")
|
||||
printAndVerifyTimeline(t, alicesGroup.Timeline)
|
||||
printAndVerifyTimeline(t, alicesGroup.GetTimeline())
|
||||
|
||||
bobsGroup := bob.Profile.Groups[groupId]
|
||||
bobsGroup := bob.Profile.GetGroupByGroupID(groupId)
|
||||
fmt.Printf("bob Groups:\n")
|
||||
for k := range bob.Profile.Groups {
|
||||
fmt.Println(" " + k)
|
||||
}
|
||||
if bobsGroup == nil {
|
||||
t.Error("bobGroup == nil")
|
||||
return
|
||||
}
|
||||
fmt.Printf("Bob TimeLine:\n")
|
||||
printAndVerifyTimeline(t, bobsGroup.Timeline)
|
||||
printAndVerifyTimeline(t, bobsGroup.GetTimeline())
|
||||
|
||||
if len(alicesGroup.Timeline.Messages) != 6 {
|
||||
t.Errorf("Alice's timeline does not have all messages")
|
||||
|
|
Loading…
Reference in New Issue