Skip to content

Commit 58369ef

Browse files
authored
Merge pull request #25 from github/more-tests
Add some more tests and improve some existing ones
2 parents 38371e9 + b516251 commit 58369ef

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

git_sizer_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestBomb(t *testing.T) {
160160
defer os.RemoveAll(repo.Path())
161161

162162
h, err := sizes.ScanRepositoryUsingGraph(
163-
repo, git.AllReferencesFilter, sizes.NameStyleNone, false,
163+
repo, git.AllReferencesFilter, sizes.NameStyleFull, false,
164164
)
165165
if !assert.NoError(err) {
166166
return
@@ -169,31 +169,42 @@ func TestBomb(t *testing.T) {
169169
assert.Equal(counts.Count32(1), h.UniqueCommitCount, "unique commit count")
170170
assert.Equal(counts.Count64(169), h.UniqueCommitSize, "unique commit size")
171171
assert.Equal(counts.Count32(169), h.MaxCommitSize, "max commit size")
172+
assert.Equal("refs/heads/master", h.MaxCommitSizeCommit.Path(), "max commit size commit")
172173
assert.Equal(counts.Count32(1), h.MaxHistoryDepth, "max history depth")
173174
assert.Equal(counts.Count32(0), h.MaxParentCount, "max parent count")
175+
assert.Equal("refs/heads/master", h.MaxParentCountCommit.Path(), "max parent count commit")
174176

175177
assert.Equal(counts.Count32(10), h.UniqueTreeCount, "unique tree count")
176178
assert.Equal(counts.Count64(2910), h.UniqueTreeSize, "unique tree size")
177179
assert.Equal(counts.Count64(100), h.UniqueTreeEntries, "unique tree entries")
178180
assert.Equal(counts.Count32(10), h.MaxTreeEntries, "max tree entries")
181+
assert.Equal("refs/heads/master:d0/d0/d0/d0/d0/d0/d0/d0/d0", h.MaxTreeEntriesTree.Path(), "max tree entries tree")
179182

180183
assert.Equal(counts.Count32(1), h.UniqueBlobCount, "unique blob count")
181184
assert.Equal(counts.Count64(6), h.UniqueBlobSize, "unique blob size")
182185
assert.Equal(counts.Count32(6), h.MaxBlobSize, "max blob size")
186+
assert.Equal("refs/heads/master:d0/d0/d0/d0/d0/d0/d0/d0/d0/f0", h.MaxBlobSizeBlob.Path(), "max blob size blob")
183187

184188
assert.Equal(counts.Count32(0), h.UniqueTagCount, "unique tag count")
185189
assert.Equal(counts.Count32(0), h.MaxTagDepth, "max tag depth")
186190

187191
assert.Equal(counts.Count32(1), h.ReferenceCount, "reference count")
188192

189193
assert.Equal(counts.Count32(11), h.MaxPathDepth, "max path depth")
194+
assert.Equal("refs/heads/master^{tree}", h.MaxPathDepthTree.Path(), "max path depth tree")
190195
assert.Equal(counts.Count32(29), h.MaxPathLength, "max path length")
196+
assert.Equal("refs/heads/master^{tree}", h.MaxPathLengthTree.Path(), "max path length tree")
191197

192198
assert.Equal(counts.Count32((pow(10, 10)-1)/(10-1)), h.MaxExpandedTreeCount, "max expanded tree count")
199+
assert.Equal("refs/heads/master^{tree}", h.MaxExpandedTreeCountTree.Path(), "max expanded tree count tree")
193200
assert.Equal(counts.Count32(0xffffffff), h.MaxExpandedBlobCount, "max expanded blob count")
201+
assert.Equal("refs/heads/master^{tree}", h.MaxExpandedBlobCountTree.Path(), "max expanded blob count tree")
194202
assert.Equal(counts.Count64(6*pow(10, 10)), h.MaxExpandedBlobSize, "max expanded blob size")
203+
assert.Equal("refs/heads/master^{tree}", h.MaxExpandedBlobSizeTree.Path(), "max expanded blob size tree")
195204
assert.Equal(counts.Count32(0), h.MaxExpandedLinkCount, "max expanded link count")
205+
assert.Nil(h.MaxExpandedLinkCountTree, "max expanded link count tree")
196206
assert.Equal(counts.Count32(0), h.MaxExpandedSubmoduleCount, "max expanded submodule count")
207+
assert.Nil(h.MaxExpandedSubmoduleCountTree, "max expanded submodule count tree")
197208
}
198209

199210
func TestTaggedTags(t *testing.T) {
@@ -287,7 +298,7 @@ func TestSubmodule(t *testing.T) {
287298
addFile(t, submPath, submRepo, "submfile2.txt", "Hello again, submodule!\n")
288299
addFile(t, submPath, submRepo, "submfile3.txt", "Hello again, submodule!\n")
289300

290-
cmd = gitCommand(t, submRepo, "commit", "-m", "main initial")
301+
cmd = gitCommand(t, submRepo, "commit", "-m", "subm initial")
291302
addAuthorInfo(cmd, &timestamp)
292303
require.NoError(t, cmd.Run(), "creating subm commit")
293304

@@ -298,7 +309,7 @@ func TestSubmodule(t *testing.T) {
298309
require.NoError(t, err, "initializing main Repository object")
299310
addFile(t, mainPath, mainRepo, "mainfile.txt", "Hello, main!\n")
300311

301-
cmd = gitCommand(t, mainRepo, "commit", "-m", "subm initial")
312+
cmd = gitCommand(t, mainRepo, "commit", "-m", "main initial")
302313
addAuthorInfo(cmd, &timestamp)
303314
require.NoError(t, cmd.Run(), "creating main commit")
304315

@@ -307,13 +318,18 @@ func TestSubmodule(t *testing.T) {
307318
cmd.Dir = mainPath
308319
require.NoError(t, cmd.Run(), "adding submodule")
309320

321+
cmd = gitCommand(t, mainRepo, "commit", "-m", "add submodule")
322+
addAuthorInfo(cmd, &timestamp)
323+
require.NoError(t, cmd.Run(), "committing submodule to main")
324+
310325
// Analyze the main repo:
311326
h, err := sizes.ScanRepositoryUsingGraph(
312327
mainRepo, git.AllReferencesFilter, sizes.NameStyleNone, false,
313328
)
314329
require.NoError(t, err, "scanning repository")
315-
assert.Equal(t, counts.Count32(1), h.UniqueBlobCount, "unique blob count")
316-
assert.Equal(t, counts.Count32(1), h.MaxExpandedBlobCount, "max expanded blob count")
330+
assert.Equal(t, counts.Count32(2), h.UniqueBlobCount, "unique blob count")
331+
assert.Equal(t, counts.Count32(2), h.MaxExpandedBlobCount, "max expanded blob count")
332+
assert.Equal(t, counts.Count32(1), h.MaxExpandedSubmoduleCount, "max expanded submodule count")
317333

318334
// Analyze the submodule:
319335
submRepo2, err := git.NewRepository(filepath.Join(mainPath, "sub"))

0 commit comments

Comments
 (0)