func (s *ConversationSuite) Test_sendAll_returnsTheFirstErrorEncountered(c *C) { cb := &conversation{"*****@*****.**", "", &otr3.Conversation{}} ts := &testSender{err: errors.New("hello")} e := cb.sendAll(ts, "", []otr3.ValidMessage{otr3.ValidMessage([]byte("Hello there"))}) c.Assert(e, DeepEquals, errors.New("hello")) }
func (s *ConversationSuite) Test_sendAll_sendsTheMessageGiven(c *C) { cb := &conversation{"*****@*****.**", "", &otr3.Conversation{}} ts := &testSender{err: nil} e := cb.sendAll(ts, "", []otr3.ValidMessage{otr3.ValidMessage([]byte("Hello there"))}) c.Assert(e, IsNil) c.Assert(ts.peer, Equals, "*****@*****.**") c.Assert(ts.msg, Equals, "Hello there") }
// Send implements server.Send func (s *server) Send(ctx context.Context, in *pb.OtrMsgRequest) (*pb.OtrMsgResponse, error) { fmt.Println("Send Message Conv uuid:", in.Uuid) conv := s.convs[in.Uuid] toSend, err := conv.Send(otr3.ValidMessage(in.Message)) if err != nil { return &pb.OtrMsgResponse{Error: err.Error()}, nil } return &pb.OtrMsgResponse{ToSend: string(toSend[0])}, nil }
// Receive implements server.Receive func (s *server) Receive(ctx context.Context, in *pb.OtrMsgRequest) (*pb.OtrMsgResponse, error) { fmt.Println("Receive Message Conv uuid:", in.Uuid) conv := s.convs[in.Uuid] plain, toSend, err := conv.Receive(otr3.ValidMessage(in.Message)) if err != nil { return &pb.OtrMsgResponse{Error: err.Error()}, nil } if toSend == nil { return &pb.OtrMsgResponse{Plain: string(plain)}, nil } return &pb.OtrMsgResponse{Plain: string(plain), ToSend: string(toSend[0])}, nil }