-
Notifications
You must be signed in to change notification settings - Fork 17
/
fixtures_test.go
162 lines (133 loc) · 3.8 KB
/
fixtures_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package fixtures_test
import (
"strconv"
"testing"
fixtures "github.com/go-git/go-git-fixtures/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDotGit(t *testing.T) {
t.Parallel()
fs := fixtures.Basic().One().DotGit(fixtures.WithTargetDir(t.TempDir))
files, err := fs.ReadDir("/")
require.NoError(t, err)
assert.Greater(t, len(files), 1)
fs = fixtures.Basic().One().DotGit(fixtures.WithMemFS())
files, err = fs.ReadDir("/")
require.NoError(t, err)
assert.Greater(t, len(files), 1)
}
//nolint:cyclop
func TestEmbeddedFiles(t *testing.T) {
t.Parallel()
for i, f := range fixtures.All() {
if f.PackfileHash != "" {
if f.Packfile() == nil {
assert.Fail(t, "failed to get pack file", i)
}
// skip pack file ee4fef0 as it does not have an idx file.
if f.PackfileHash != "ee4fef0ef8be5053ebae4ce75acf062ddf3031fb" && f.Idx() == nil {
assert.Fail(t, "failed to get idx file", i)
}
}
if f.WorktreeHash != "" {
if f.Worktree(fixtures.WithMemFS()) == nil {
assert.Fail(t, "[mem] failed to get worktree", i)
}
if f.Worktree(fixtures.WithTargetDir(t.TempDir)) == nil {
assert.Fail(t, "[tempdir] failed to get worktree", i)
}
}
if f.DotGitHash != "" {
if f.DotGit(fixtures.WithMemFS()) == nil {
assert.Fail(t, "[mem] failed to get dotgit", i)
}
if f.DotGit(fixtures.WithTargetDir(t.TempDir)) == nil {
assert.Fail(t, "[tempdir] failed to get dotgit", i)
}
}
}
}
func TestRevFiles(t *testing.T) {
t.Parallel()
f := fixtures.ByTag("packfile-sha256").One()
assert.NotNil(t, f)
assert.NotNil(t, f.Rev(), "failed to get rev file")
}
func TestAll(t *testing.T) {
t.Parallel()
fs := fixtures.All()
assert.Len(t, fs, 38)
}
func TestByTag(t *testing.T) {
t.Parallel()
tests := []struct {
tag string
len int
}{
{tag: "packfile", len: 20},
{tag: "ofs-delta", len: 3},
{tag: ".git", len: 12},
{tag: "merge-conflict", len: 1},
{tag: "worktree", len: 6},
{tag: "submodule", len: 1},
{tag: "tags", len: 1},
{tag: "notes", len: 1},
{tag: "multi-packfile", len: 1},
{tag: "diff-tree", len: 7},
{tag: "packfile-sha256", len: 1},
}
for _, tc := range tests {
tc := tc
t.Run(tc.tag, func(t *testing.T) {
t.Parallel()
f := fixtures.ByTag(tc.tag)
assert.Len(t, f, tc.len)
})
}
}
func TestByURL(t *testing.T) {
t.Parallel()
tests := []struct {
URL string
len int
}{
{URL: "https://github.com/git-fixtures/root-references.git", len: 1},
{URL: "https://github.com/git-fixtures/basic.git", len: 9},
{URL: "https://github.com/git-fixtures/submodule.git", len: 1},
{URL: "https://github.com/src-d/go-git.git", len: 1},
{URL: "https://github.com/git-fixtures/tags.git", len: 1},
{URL: "https://github.com/spinnaker/spinnaker.git", len: 1},
{URL: "https://github.com/jamesob/desk.git", len: 1},
{URL: "https://github.com/cpcs499/Final_Pres_P.git", len: 1},
{URL: "https://github.com/github/gem-builder.git", len: 1},
{URL: "https://github.com/githubtraining/example-branches.git", len: 1},
{URL: "https://github.com/rumpkernel/rumprun-xen.git", len: 1},
{URL: "https://github.com/mcuadros/skeetr.git", len: 1},
{URL: "https://github.com/dezfowler/LiteMock.git", len: 1},
{URL: "https://github.com/tyba/storable.git", len: 1},
{URL: "https://github.com/toqueteos/ts3.git", len: 1},
{URL: "https://github.com/git-fixtures/empty.git", len: 1},
}
for _, tc := range tests {
tc := tc
t.Run(tc.URL, func(t *testing.T) {
t.Parallel()
f := fixtures.ByURL(tc.URL)
assert.Len(t, f, tc.len)
})
}
}
func TestIdx(t *testing.T) {
t.Parallel()
for i, f := range fixtures.ByTag("packfile") {
f := f
t.Run("#"+strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
index := f.Idx()
assert.NotNil(t, index)
err := index.Close()
assert.NoError(t, err)
})
}
}