This repository has been archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_test.go
88 lines (83 loc) · 1.83 KB
/
template_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package state
import (
"encoding/json"
"testing"
"github.com/google/go-github/v24/github"
"github.com/stretchr/testify/require"
)
func TestNewTemplate(t *testing.T) {
type testcase struct {
name string
entryJSON string
expected *Template
}
cases := []testcase{
{
"tree",
`{
"path": ".github",
"mode": "040000",
"type": "tree",
"sha": "45f58ef9211cc06f3ef86585c7ecb1b3d52fd4f9",
"url":
"https://api.github.com/repos/github/gitignore/git/trees/45f58ef9211cc06f3ef86585c7ecb1b3d52fd4f9"
}`,
nil,
},
{
"travis.yml",
`{
"path": ".travis.yml",
"mode": "100644",
"type": "blob",
"sha": "f362d6fe3228d49e1658e8e66ffbd8ec52ab86c7",
"size": 103,
"url":
"https://api.github.com/repos/github/gitignore/git/blobs/f362d6fe3228d49e1658e8e66ffbd8ec52ab86c7"
}`,
nil,
},
{
"actionscript",
`{
"path": "Actionscript.gitignore",
"mode": "100644",
"sha": "5d947ca8879f8a9072fe485c566204e3c2929e80",
"size": 350,
"url":
"https://api.github.com/repos/github/gitignore/git/blobs/5d947ca8879f8a9072fe485c566204e3c2929e80"
}`,
&Template{
"Actionscript",
350,
"Actionscript.gitignore",
nil,
"5d947ca8879f8a9072fe485c566204e3c2929e80",
},
},
{
"gitignore",
`{
"path": ".gitignore",
"mode": "100644",
"type": "blob",
"sha": "eba3b7ec8af85c99af1a6c8f375c2ba8a92befc6",
"size": 3601,
"url":
"https://api.github.com/repos/demosdemon/dotfiles/git/blobs/eba3b7ec8af85c99af1a6c8f375c2ba8a92befc6"
}`,
nil,
},
}
t.Parallel()
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
var entry github.TreeEntry
err := json.Unmarshal([]byte(tt.entryJSON), &entry)
require.NoError(t, err)
tpl := NewTemplate(entry)
require.Equal(t, tt.expected, tpl)
})
}
}