forked from sosedoff/gitkit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
hook_info_test.go
54 lines (48 loc) · 1.56 KB
/
hook_info_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
package gitkit
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ReadHookInput(t *testing.T) {
input := "e285100b636ac67fa28d85685072158edaa01685 a3d33576d686e7dc1d90ec4b1a6e94e760a893b2 refs/heads/master\n"
info, err := ReadHookInput(strings.NewReader(input))
assert.NoError(t, err)
assert.Equal(t, "e285100b636ac67fa28d85685072158edaa01685", info.OldRev)
assert.Equal(t, "a3d33576d686e7dc1d90ec4b1a6e94e760a893b2", info.NewRev)
assert.Equal(t, "refs/heads/master", info.Ref)
assert.Equal(t, "heads", info.RefType)
assert.Equal(t, "master", info.RefName)
}
func Test_HookAction(t *testing.T) {
examples := map[string]HookInfo{
"branch.create": HookInfo{
OldRev: "0000000000000000000000000000000000000000",
NewRev: "e285100b636ac67fa28d85685072158edaa01685",
RefType: "heads",
},
"branch.delete": HookInfo{
OldRev: "e285100b636ac67fa28d85685072158edaa01685",
NewRev: "0000000000000000000000000000000000000000",
RefType: "heads",
},
"branch.push": HookInfo{
OldRev: "e285100b636ac67fa28d85685072158edaa01685",
NewRev: "a3d33576d686e7dc1d90ec4b1a6e94e760a893b2",
RefType: "heads",
},
"tag.create": HookInfo{
OldRev: "0000000000000000000000000000000000000000",
NewRev: "e285100b636ac67fa28d85685072158edaa01685",
RefType: "tags",
},
"tag.delete": HookInfo{
OldRev: "e285100b636ac67fa28d85685072158edaa01685",
NewRev: "0000000000000000000000000000000000000000",
RefType: "tags",
},
}
for expected, hook := range examples {
assert.Equal(t, expected, parseHookAction(hook))
}
}