forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks_test.go
More file actions
64 lines (53 loc) · 2.05 KB
/
hooks_test.go
File metadata and controls
64 lines (53 loc) · 2.05 KB
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
61
62
63
64
package gogitlab
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
func TestHook(t *testing.T) {
ts, gitlab := Stub("stubs/hooks/show.json")
hook, err := gitlab.ProjectHook("1", "2")
assert.Equal(t, err, nil)
assert.IsType(t, new(Hook), hook)
assert.Equal(t, hook.Url, "http://example.com/hook")
defer ts.Close()
}
func TestParsePushHook(t *testing.T) {
stub, _ := ioutil.ReadFile("stubs/hooks/push.json")
p, err := ParseHook([]byte(stub))
assert.Equal(t, err, nil)
assert.IsType(t, new(HookPayload), p)
assert.Equal(t, p.After, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7")
assert.Equal(t, p.Repository.URL, "git@localhost:diaspora.git")
assert.Equal(t, len(p.Commits), 2)
assert.Equal(t, p.Commits[0].Author.Email, "jordi@softcatala.org")
assert.Equal(t, p.Commits[1].Id, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7")
assert.Equal(t, p.Branch(), "master")
assert.Equal(t, p.Head().Message, "fixed readme")
}
func TestParseIssueHook(t *testing.T) {
stub, _ := ioutil.ReadFile("stubs/hooks/issue.json")
p, err := ParseHook([]byte(stub))
assert.Equal(t, err, nil)
assert.Equal(t, p.ObjectKind, "issue")
assert.Equal(t, p.ObjectAttributes.Id, 301)
}
func TestParseMergeRequestHook(t *testing.T) {
stub, _ := ioutil.ReadFile("stubs/hooks/merge_request.json")
p, err := ParseHook([]byte(stub))
assert.Equal(t, err, nil)
assert.Equal(t, p.ObjectKind, "merge_request")
assert.Equal(t, p.ObjectAttributes.TargetBranch, "master")
assert.Equal(t, p.ObjectAttributes.SourceProjectId, p.ObjectAttributes.TargetProjectId)
}
func TestParsePipelineHook(t *testing.T) {
stub, _ := ioutil.ReadFile("stubs/hooks/pipeline.json")
p, err := ParseHook([]byte(stub))
assert.Equal(t, err, nil)
assert.IsType(t, new(HookPayload), p)
assert.Equal(t, p.ObjectAttributes.Sha, "bcbb5ec396a2c0f828686f14fac9b80b780504f2")
assert.Equal(t, p.Project.Description, "Atque in sunt eos similique dolores voluptatem.")
assert.Equal(t, p.Commit.Id, "bcbb5ec396a2c0f828686f14fac9b80b780504f2")
assert.Equal(t, p.Branch(), "master")
assert.Equal(t, p.Builds[0].Id, 380)
}