Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6KB

  1. package bridge
  2. import (
  3. "cwtch.im/cwtch/event"
  4. "testing"
  5. )
  6. var (
  7. clientPipe = "./client"
  8. servicePipe = "./service"
  9. )
  10. func clientHelper(t *testing.T, in, out string, messageOrig *event.IPCMessage, done chan bool) {
  11. client := NewPipeBridgeClient(in, out)
  12. messageAfter, ok := client.Read()
  13. if !ok {
  14. t.Errorf("Reading from client IPCBridge failed")
  15. done <- true
  16. return
  17. }
  18. if messageOrig.Dest != messageAfter.Dest {
  19. t.Errorf("Dest's value differs expected: %v actaul: %v", messageOrig.Dest, messageAfter.Dest)
  20. }
  21. if messageOrig.Message.EventType != messageAfter.Message.EventType {
  22. t.Errorf("EventTypes's value differs expected: %v actaul: %v", messageOrig.Message.EventType, messageAfter.Message.EventType)
  23. }
  24. if messageOrig.Message.Data[event.Identity] != messageAfter.Message.Data[event.Identity] {
  25. t.Errorf("Data[Identity]'s value differs expected: %v actaul: %v", messageOrig.Message.Data[event.Identity], messageAfter.Message.Data[event.Identity])
  26. }
  27. done <- true
  28. }
  29. func serviceHelper(t *testing.T, in, out string, messageOrig *event.IPCMessage, done chan bool) {
  30. service, err := NewPipeBridgeService(in, out)
  31. if err != nil {
  32. t.Errorf("Error opening %v pipe: %v", in, err)
  33. done <- true
  34. return
  35. }
  36. service.Write(messageOrig)
  37. done <- true
  38. }
  39. func TestPipeBridge(t *testing.T) {
  40. messageOrig := &event.IPCMessage{Dest: "ABC", Message: event.NewEventList(event.NewPeer, event.Identity, "It is I")}
  41. serviceDone := make(chan bool)
  42. clientDone := make(chan bool)
  43. go clientHelper(t, clientPipe, servicePipe, messageOrig, clientDone)
  44. go serviceHelper(t, servicePipe, clientPipe, messageOrig, serviceDone)
  45. <-serviceDone
  46. <-clientDone
  47. }