-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsse_test.go
53 lines (45 loc) · 972 Bytes
/
sse_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
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"testing"
"time"
"github.com/gocontrib/rest"
"github.com/stretchr/testify/assert"
)
func TestEventStream(t *testing.T) {
port := os.Getenv("HTTP_PORT")
host := fmt.Sprintf("http://localhost:%s", port)
client := rest.NewClient(rest.Config{
BaseURL: host,
Authorization: "local_admin",
Verbose: true,
})
events := make(chan *rest.Event, 1)
die := make(chan bool)
timer := time.NewTimer(5 * time.Second)
go func() {
fmt.Println("READING EVENT STREAM")
err := client.EventStream("/api/event/stream", events)
assert.Nil(t, err)
<-die
close(events)
}()
go func() {
time.Sleep(1 * time.Second)
fmt.Println("POST DATA")
var result map[string]interface{}
err := client.Post("/api/data/user", &TestUser{
Name: "bob",
Age: 21,
}, &result)
assert.Nil(t, err)
}()
select {
case e := <-events:
assert.NotNil(t, e)
case <-timer.C:
assert.Fail(t, "timeout")
}
die <- true
}