forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
46 lines (43 loc) · 1.02 KB
/
reader_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
34
35
36
37
38
39
40
41
42
43
44
45
46
package file
import (
"fmt"
"path/filepath"
"testing"
"github.com/compose/transporter/adaptor"
"github.com/compose/transporter/client"
)
func TestRead(t *testing.T) {
a, err := adaptor.GetAdaptor(
"file",
map[string]interface{}{"uri": fmt.Sprintf("file://%s", filepath.Join("testdata", "start_test.json"))},
)
if err != nil {
t.Fatalf("unexpected GetV2() error, %s", err)
}
c, err := a.Client()
if err != nil {
t.Errorf("unexpected Client() error, %s", err)
}
s, err := c.Connect()
if err != nil {
t.Fatalf("unexpected Connect() error, %s", err)
}
r, err := a.Reader()
if err != nil {
t.Fatalf("unexpected Reader() error, %s", err)
}
readFunc := r.Read(map[string]client.MessageSet{}, func(string) bool { return true })
done := make(chan struct{})
defer close(done)
msgChan, err := readFunc(s, done)
if err != nil {
t.Fatalf("unexpected Read() error, %s", err)
}
var count int
for range msgChan {
count++
}
if count != 10 {
t.Errorf("unexpected message count, expected %d, got %d\n", 10, 10)
}
}