expand integ test:
- run own server - alice & bob users - chat - pretty print results TODO: disconnect and reconnect to confirm offline delivery TODO: tidy up
This commit is contained in:
parent
0715c4ce0b
commit
36d0e3786c
|
@ -1,22 +1,104 @@
|
|||
package testing
|
||||
|
||||
import (
|
||||
cwtchserver "git.mascherari.press/cwtch/server"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"git.mascherari.press/cwtch/peer"
|
||||
"testing"
|
||||
"time"
|
||||
"log"
|
||||
"git.mascherari.press/cwtch/protocol"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"io/ioutil"
|
||||
"fmt"
|
||||
"git.mascherari.press/cwtch/model"
|
||||
)
|
||||
|
||||
func TestCwtchPeerIntegration(t *testing.T) {
|
||||
alice := peer.NewCwtchPeer("Alice")
|
||||
id, _ := alice.Profile.StartGroup("ylhbhtypevo4ympq")
|
||||
alice.Profile.AddContact(alice.Profile.Onion, alice.Profile.PublicProfile)
|
||||
alice.JoinServer("ylhbhtypevo4ympq")
|
||||
// time.Sleep(time.Second *5)
|
||||
alice.SendMessageToGroup(id, "Hello")
|
||||
alice.SendMessageToGroup(id, "My")
|
||||
alice.SendMessageToGroup(id, "Name Is")
|
||||
alice.SendMessageToGroup(id, "ALICE!!!")
|
||||
time.Sleep(time.Second * 5)
|
||||
group := alice.Profile.Groups[id]
|
||||
t.Logf("%v", group.Timeline)
|
||||
const (
|
||||
server = "kwke2hntvyfqm7dr"//"ylhbhtypevo4ympq"
|
||||
keyfile = "./private_key"
|
||||
)
|
||||
|
||||
var (
|
||||
aliceLines = []string {"Hello", "My name is Alice", "bye"}
|
||||
bobLines = []string {"Hi", "My name is Bob.", "toodles", "hello?"}
|
||||
|
||||
)
|
||||
|
||||
func printTimeline(timeline model.Timeline) {
|
||||
for _, message := range timeline.Messages {
|
||||
fmt.Printf("%v %v> %s [%t]\n", message.Timestamp, message.PeerID, message.Message, message.Verified)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCwtchPeerIntegration(t *testing.T) {
|
||||
// Hide logging "noise"
|
||||
log.SetOutput(ioutil.Discard)
|
||||
|
||||
// launch app
|
||||
server := new(cwtchserver.Server)
|
||||
fmt.Println("starting cwtch server...")
|
||||
go server.Run(keyfile)
|
||||
|
||||
server_key, err := utils.LoadPrivateKeyFromFile(keyfile)
|
||||
if err != nil {
|
||||
log.Fatal("Could not load server's key from %v", keyfile)
|
||||
}
|
||||
server_addr, _ := utils.GetOnionAddress(server_key)
|
||||
|
||||
// let tor get established
|
||||
fmt.Printf("Establishing Tor hidden service: %v...\n", server_addr)
|
||||
time.Sleep(time.Second * 60)
|
||||
|
||||
// launch alice
|
||||
alice := peer.NewCwtchPeer("Alice")
|
||||
groupId, invite := alice.Profile.StartGroup(server_addr)
|
||||
gci := &protocol.CwtchPeerPacket{}
|
||||
proto.Unmarshal(invite, gci)
|
||||
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)
|
||||
fmt.Println("Bob joining group...")
|
||||
bob.JoinServer(server_addr)
|
||||
|
||||
fmt.Println("Alice> ", aliceLines[0])
|
||||
alice.SendMessageToGroup(groupId, aliceLines[0])
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
fmt.Println("Bob> ", bobLines[0])
|
||||
bob.SendMessageToGroup(groupId, bobLines[0])
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
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)
|
||||
|
||||
fmt.Println("Alice> ", aliceLines[2])
|
||||
alice.SendMessageToGroup(groupId, aliceLines[2])
|
||||
// Todo: Alice disconnects
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
fmt.Println("Bob> ", bobLines[2])
|
||||
bob.SendMessageToGroup(groupId, bobLines[2])
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
|
||||
// Todo: Alice reconects, gets missed messages (from bob)
|
||||
|
||||
alicesGroup := alice.Profile.Groups[groupId]
|
||||
fmt.Printf("Alice TimeLine:\n")
|
||||
printTimeline(alicesGroup.Timeline)
|
||||
|
||||
bobsGroup := bob.Profile.Groups[groupId]
|
||||
fmt.Printf("Bob TimeLine:\n")
|
||||
printTimeline(bobsGroup.Timeline)
|
||||
|
||||
// Todo: shutdown users and server
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue