-
Notifications
You must be signed in to change notification settings - Fork 0
/
payload_test.go
58 lines (56 loc) · 1.47 KB
/
payload_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
54
55
56
57
58
package main
import (
"encoding/json"
"io"
"net/http"
"testing"
)
func Test_ParseJson(t *testing.T) {
client := new(http.Client)
req, _ := http.NewRequest("GET", "https://raw.githubusercontent.com/go-playground/webhooks/master/testdata/github/pull-request.json", nil)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
t.Error(err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Status not OK, %v", resp.StatusCode)
}
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
playload := new(PullRequestEvent)
err = json.Unmarshal(bodyText, playload)
if err != nil {
t.Error(err)
}
}
func Test_Test_UUID_Generation(t *testing.T) {
setupTestlogging()
client := new(http.Client)
req, _ := http.NewRequest("GET", "https://raw.githubusercontent.com/go-playground/webhooks/master/testdata/github/pull-request.json", nil)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
t.Error(err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Status not OK, %v", resp.StatusCode)
}
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
playload := new(PullRequestEvent)
err = json.Unmarshal(bodyText, playload)
if err != nil {
t.Error(err)
}
wantUUID := "c39b05e9-4c8e-aa2e-8e6d-f3b47804e88d"
uuid := playload.PullRequest.generateUUID()
if uuid != wantUUID {
t.Errorf("%v does not match %v", uuid, wantUUID)
}
t.Logf("uuid: %v", uuid)
}