-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebhooksite_test.go
More file actions
56 lines (46 loc) · 917 Bytes
/
webhooksite_test.go
File metadata and controls
56 lines (46 loc) · 917 Bytes
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
54
55
56
package webhooksite
import (
"net/http"
"testing"
)
func notNil(t *testing.T, v interface{}) {
if v == nil {
t.Fail()
}
}
func noError(t *testing.T, err error) {
if err != nil {
t.Logf("Unexpected error: %s", err)
t.Fail()
}
}
func hasLen(t *testing.T, coll []*Request, count int) {
if len(coll) != count {
t.Logf("Unexpected length: %d != %d", len(coll), count)
t.Fail()
}
}
func TestWebhooks(t *testing.T) {
t.Parallel()
c := New()
notNil(t, c)
token, err := c.CreateToken()
noError(t, err)
notNil(t, token)
reqs, err := c.GetRequests(token.UUID)
noError(t, err)
notNil(t, reqs)
hasLen(t, reqs.Data, 0)
// Do a webhook call
resp, err := http.Get(token.URL)
noError(t, err)
if resp.StatusCode != http.StatusOK {
t.Fail()
}
defer resp.Body.Close()
// Should have it now
reqs, err = c.GetRequests(token.UUID)
noError(t, err)
notNil(t, reqs)
hasLen(t, reqs.Data, 1)
}