github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+incompatible/lfs/lfs_test.go (about) 1 package lfs_test // avoid import cycle 2 3 import ( 4 "fmt" 5 "sort" 6 "testing" 7 8 "github.com/git-lfs/git-lfs/lfs" 9 "github.com/git-lfs/git-lfs/test" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestAllCurrentObjectsNone(t *testing.T) { 14 repo := test.NewRepo(t) 15 repo.Pushd() 16 defer func() { 17 repo.Popd() 18 repo.Cleanup() 19 }() 20 21 actual := lfs.AllObjects() 22 if len(actual) > 0 { 23 for _, file := range actual { 24 t.Logf("Found: %v", file) 25 } 26 t.Error("Should be no objects") 27 } 28 } 29 30 func TestAllCurrentObjectsSome(t *testing.T) { 31 repo := test.NewRepo(t) 32 repo.Pushd() 33 defer func() { 34 repo.Popd() 35 repo.Cleanup() 36 }() 37 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 40 numFiles := 20 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}) 45 } 46 47 inputs := []*test.CommitInput{ 48 {Files: files}, 49 } 50 51 outputs := repo.AddCommits(inputs) 52 53 expected := make([]*lfs.Pointer, 0, numFiles) 54 for _, f := range outputs[0].Files { 55 expected = append(expected, f) 56 } 57 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) 62 } 63 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") 68 69 }