-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_test.go
60 lines (53 loc) · 1.55 KB
/
event_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
59
60
package main
import (
"encoding/json"
"testing"
)
func TestDeserializeRepoUpdate(t *testing.T) {
exampleUpdate := `
{
"event_name": "repository_update",
"user_id": 1,
"user_name": "John Smith",
"user_email": "[email protected]",
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
"project_id": 1,
"project": {
"name":"Example",
"description":"",
"web_url":"http://example.com/jsmith/example",
"avatar_url":null,
"git_ssh_url":"[email protected]:jsmith/example.git",
"git_http_url":"http://example.com/jsmith/example.git",
"namespace":"Jsmith",
"visibility_level":0,
"path_with_namespace":"jsmith/example",
"default_branch":"master",
"homepage":"http://example.com/jsmith/example",
"url":"[email protected]:jsmith/example.git",
"ssh_url":"[email protected]:jsmith/example.git",
"http_url":"http://example.com/jsmith/example.git"
},
"changes": [
{
"before":"8205ea8d81ce0c6b90fbe8280d118cc9fdad6130",
"after":"4045ea7a3df38697b3730a20fb73c8bed8a3e69e",
"ref":"refs/heads/master"
}
],
"refs":["refs/heads/master"]
}
`
var got RepositoryUpdate
bytes := []byte(exampleUpdate)
err := json.Unmarshal(bytes, &got)
if err != nil {
t.Errorf("Error deserializing: %v", err)
}
if got.Name != "repository_update" {
t.Errorf("Expected repository_update, got %v", got.Name)
}
if got.Project.Name != "Example" {
t.Errorf("Expected name to be Example, got: %v", got.Project.Name)
}
}