1 package lfs_test // avoid import cycle
8 "github.com/git-lfs/git-lfs/lfs"
9 "github.com/git-lfs/git-lfs/test"
10 "github.com/stretchr/testify/assert"
13 func TestAllCurrentObjectsNone(t *testing.T) {
14 repo := test.NewRepo(t)
21 actual := lfs.AllObjects()
23 for _, file := range actual {
24 t.Logf("Found: %v", file)
26 t.Error("Should be no objects")
30 func TestAllCurrentObjectsSome(t *testing.T) {
31 repo := test.NewRepo(t)
38 // We're not testing commits here, just storage, so just create a single
39 // commit input with lots of files to generate many oids
41 files := make([]*test.FileInput, 0, numFiles)
42 for i := 0; i < numFiles; i++ {
43 // Must be >=16 bytes for each file to be unique
44 files = append(files, &test.FileInput{Filename: fmt.Sprintf("file%d.txt", i), Size: 30})
47 inputs := []*test.CommitInput{
51 outputs := repo.AddCommits(inputs)
53 expected := make([]*lfs.Pointer, 0, numFiles)
54 for _, f := range outputs[0].Files {
55 expected = append(expected, f)
58 actualObjects := lfs.AllObjects()
59 actual := make([]*lfs.Pointer, len(actualObjects))
60 for idx, f := range actualObjects {
61 actual[idx] = lfs.NewPointer(f.Oid, f.Size, nil)
64 // sort to ensure comparison is equal
65 sort.Sort(test.PointersByOid(expected))
66 sort.Sort(test.PointersByOid(actual))
67 assert.Equal(t, expected, actual, "Oids from disk should be the same as in commits")