forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlfs_test.go
69 lines (57 loc) · 1.55 KB
/
lfs_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
package lfs_test // avoid import cycle
import (
"fmt"
"sort"
"testing"
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/test"
"github.com/stretchr/testify/assert"
)
func TestAllCurrentObjectsNone(t *testing.T) {
repo := test.NewRepo(t)
repo.Pushd()
defer func() {
repo.Popd()
repo.Cleanup()
}()
actual := lfs.AllObjects()
if len(actual) > 0 {
for _, file := range actual {
t.Logf("Found: %v", file)
}
t.Error("Should be no objects")
}
}
func TestAllCurrentObjectsSome(t *testing.T) {
repo := test.NewRepo(t)
repo.Pushd()
defer func() {
repo.Popd()
repo.Cleanup()
}()
// We're not testing commits here, just storage, so just create a single
// commit input with lots of files to generate many oids
numFiles := 20
files := make([]*test.FileInput, 0, numFiles)
for i := 0; i < numFiles; i++ {
// Must be >=16 bytes for each file to be unique
files = append(files, &test.FileInput{Filename: fmt.Sprintf("file%d.txt", i), Size: 30})
}
inputs := []*test.CommitInput{
{Files: files},
}
outputs := repo.AddCommits(inputs)
expected := make([]*lfs.Pointer, 0, numFiles)
for _, f := range outputs[0].Files {
expected = append(expected, f)
}
actualObjects := lfs.AllObjects()
actual := make([]*lfs.Pointer, len(actualObjects))
for idx, f := range actualObjects {
actual[idx] = lfs.NewPointer(f.Oid, f.Size, nil)
}
// sort to ensure comparison is equal
sort.Sort(test.PointersByOid(expected))
sort.Sort(test.PointersByOid(actual))
assert.Equal(t, expected, actual, "Oids from disk should be the same as in commits")
}