-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub_test.go
48 lines (38 loc) · 1023 Bytes
/
pubsub_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
package pogifyapi
import (
"net/http"
"os"
"testing"
gonanoid "github.com/matoous/go-nanoid"
)
func Test_pubsub_pub(t *testing.T) {
p := new(pubsub)
p.url = os.Getenv("PUBSUB_URL")
ch := make(chan *http.Response)
errCh := make(chan error)
testChannel, _ := gonanoid.ID(10)
testData, _ := gonanoid.ID(20)
t.Run("missing auth header", func(t *testing.T) {
go p.pub(ch, errCh, testChannel, []byte(testData))
select {
case res := <-ch:
if res.StatusCode != http.StatusUnauthorized {
t.Errorf("pub method returned %v not %v", res.StatusCode, http.StatusUnauthorized)
}
case err := <-errCh:
t.Errorf("return error: %s", err)
}
})
t.Run("missing auth header", func(t *testing.T) {
p.secret = _pubsubsecret
go p.pub(ch, errCh, testChannel, []byte(testData))
select {
case res := <-ch:
if res.StatusCode != http.StatusOK {
t.Errorf("pub method returned %v not %v", res.StatusCode, http.StatusOK)
}
case err := <-errCh:
t.Errorf("return error: %s", err)
}
})
}