2015-09-09 14:14:37 +00:00
|
|
|
package lfs_test // avoid import cycle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/github/git-lfs/lfs"
|
|
|
|
"github.com/github/git-lfs/test"
|
|
|
|
"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAllCurrentObjectsNone(t *testing.T) {
|
|
|
|
repo := test.NewRepo(t)
|
|
|
|
repo.Pushd()
|
|
|
|
defer func() {
|
|
|
|
repo.Popd()
|
|
|
|
repo.Cleanup()
|
|
|
|
}()
|
|
|
|
|
|
|
|
actual := AllLocalObjects()
|
|
|
|
|
2015-09-11 11:54:41 +00:00
|
|
|
assert.Equal(t, []*Pointer{}, actual, "Should be no objects")
|
2015-09-09 14:14:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2015-09-11 11:54:41 +00:00
|
|
|
expected := make([]*Pointer, 0, numFiles)
|
2015-09-09 14:14:37 +00:00
|
|
|
for _, f := range outputs[0].Files {
|
2015-09-11 11:54:41 +00:00
|
|
|
expected = append(expected, f)
|
2015-09-09 14:14:37 +00:00
|
|
|
}
|
|
|
|
actual := AllLocalObjects()
|
|
|
|
|
|
|
|
// sort to ensure comparison is equal
|
2015-09-11 11:54:41 +00:00
|
|
|
sort.Sort(test.PointersByOid(expected))
|
|
|
|
sort.Sort(test.PointersByOid(actual))
|
2015-09-09 14:14:37 +00:00
|
|
|
assert.Equal(t, expected, actual, "Oids from disk should be the same as in commits")
|
|
|
|
|
|
|
|
}
|