-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgshipper_test.go
33 lines (25 loc) · 929 Bytes
/
msgshipper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Agora
import (
"bufio"
"bytes"
"github.com/verma-kartik/Agora/message"
"testing"
"github.com/onsi/gomega"
)
func TestMessageShipper_SuccessfullyForwardsMessages(t *testing.T) {
gomega.RegisterTestingT(t)
inputChannel := make(chan *message.Msg, 0)
writerBuffer := new(bytes.Buffer)
dummyWriter := bufio.NewWriter(writerBuffer)
closedChannel := make(chan bool)
dummyClient := Client{Name: "Test", Writer: dummyWriter, Closed: &closedChannel}
dummyMetricsChannel := make(chan *Metric)
underTest := newMessageShipper(inputChannel, &dummyClient, dummyMetricsChannel, "test")
testMessagePayload := []byte("This is a test!")
expectedMessagePayload := []byte("This is a test!\r\n.\r\n")
testMessage := message.NewHeaderlessMsg(&testMessagePayload)
underTest.messageChannel <- testMessage
gomega.Eventually(func() []byte {
return writerBuffer.Bytes()
}).Should(gomega.Equal(expectedMessagePayload))
}