예제 #1
0
파일: git_test.go 프로젝트: pombredanne/bar
func Test_Git_LsTree(t *testing.T) {
	tree := fixtures.NewTree("Git_LsTree", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()
	g, err := gitFixture(tree)
	assert.NoError(t, err)

	res1, err := g.LsTree("HEAD", "in-other", "one", "two/file-four with spaces.bin")
	assert.NoError(t, err)
	assert.EqualValues(t,
		[]string{
			"one/file-four with spaces.bin",
			"one/file-one.bin",
			"one/file-three.bin",
			"one/file-two.bin",
			"two/file-four with spaces.bin"}, res1)
	res2, err := g.LsTree("other", "in-other", "one")
	assert.NoError(t, err)
	assert.EqualValues(t,
		[]string{
			"in-other/blob.bin",
			"one/file-four with spaces.bin",
			"one/file-one.bin",
			"one/file-three.bin",
			"one/file-two.bin"}, res2)
}
예제 #2
0
파일: git_test.go 프로젝트: pombredanne/bar
func Test_Git_Checkout_Files(t *testing.T) {
	tree := fixtures.NewTree("Git_Checkout_files", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()
	g, err := gitFixture(tree)
	assert.NoError(t, err)
	err = g.Checkout("other",
		filepath.Join("in-other", "blob.bin"),
		filepath.Join("two", "file-four with spaces.bin"),
	)
	assert.NoError(t, err)

	// assert on branch master
	current, _, err := g.GetBranches()
	assert.NoError(t, err)
	assert.Equal(t, "master", current)

	diff, err := g.DiffIndex(
		filepath.Join("in-other", "blob.bin"),
		filepath.Join("two", "file-four with spaces.bin"),
	)
	assert.NoError(t, err)
	assert.Equal(t, []string{
		"in-other/blob.bin",
		"two/file-four with spaces.bin"}, diff)
}
예제 #3
0
func Test_Model_IsBlobs(t *testing.T) {
	tree := fixtures.NewTree("is-blob", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	names := lists.NewFileList().ListDir(tree.CWD)

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)

	_, err = m.IsBlobs(names...)
	assert.NoError(t, err)
}
예제 #4
0
func Test_Model_FeedManifests_Nil(t *testing.T) {
	tree := fixtures.NewTree("feed-manifests", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	names := lists.NewFileList().ListDir(tree.CWD)
	tree.KillBLOB("file-one.bin")

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)
	lx, err := m.FeedManifests(true, true, false, names...)
	assert.Error(t, err)
	assert.Len(t, lx.Names(), 15)
}
예제 #5
0
파일: git_test.go 프로젝트: pombredanne/bar
func Test_Git_DiffFiles(t *testing.T) {
	tree := fixtures.NewTree("Git_DiffFiles", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()
	g, err := gitFixture(tree)
	assert.NoError(t, err)

	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "in-other", "blob.bin"), 10)
	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "two", "file-four with spaces.bin"), 110)
	dirty, err := g.DiffFiles(
		filepath.Join("in-other", "blob.bin"),
		filepath.Join("two", "file-four with spaces.bin"),
	)
	assert.NoError(t, err)
	assert.Equal(t, []string{"two/file-four with spaces.bin"}, dirty)
}
예제 #6
0
func Test_Assembler_Assemble(t *testing.T) {
	tree := fixtures.NewTree("Assembler", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	ml, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	names := []string{
		"file-two.bin", "one/file-two.bin", "one/file-three.bin",
	}

	// get manifests
	mx, err := ml.FeedManifests(true, true, true,
		lists.NewFileList(names...).ListDir(tree.CWD)...)
	assert.NoError(t, err)

	a, err := model.NewAssembler(ml)
	assert.NoError(t, err)

	for name, man := range mx {
		f, err := os.Open(filepath.Join(tree.CWD, name))
		assert.NoError(t, err)
		for _, chunk := range man.Chunks {
			buf := make([]byte, chunk.Size)
			_, err = f.Read(buf)
			assert.NoError(t, err)

			err = a.StoreChunk(bytes.NewReader(buf), chunk.ID)
			assert.NoError(t, err)
		}
	}

	// Kill some blobs
	tree.KillBLOB("file-two.bin")
	tree.KillBLOB("one/file-two.bin")

	err = a.Done(mx)
	assert.NoError(t, err)

	mx1, err := ml.FeedManifests(true, true, true,
		lists.NewFileList(names...).ListDir(tree.CWD)...)
	assert.NoError(t, err)

	assert.Equal(t, mx, mx1)
}
예제 #7
0
func seed(t *testing.T, root string) (halt func(), tree *fixtures.Tree, ml *model.Model, srv *fixtures.FixtureServer, trans *transport.Transport) {
	tree = fixtures.NewTree(root, "")
	assert.NoError(t, tree.Populate())

	ml, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 32)
	assert.NoError(t, err)

	srv, err = fixtures.NewFixtureServer(root)
	assert.NoError(t, err)
	trans = transport.NewTransport(ml, srv.HTTPEndpoint, srv.RPCEndpoints[0], 16)

	halt = func() {
		trans.Close()
		srv.Stop()
		tree.Squash()
	}
	return
}
예제 #8
0
func Test_Model_FeedManifests_Many(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}
	tree := fixtures.NewTree("collect-manifests-large", "")
	defer tree.Squash()

	assert.NoError(t, tree.Populate())
	assert.NoError(t, tree.PopulateN(10, 300))

	names := lists.NewFileList().ListDir(tree.CWD)

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)
	lx, err := m.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)

	assert.Len(t, lx.Names(), 316)
}
예제 #9
0
func Benchmark_Model_FeedManifests_Large(b *testing.B) {
	tree := fixtures.NewTree("collect-manifests-large-B", "")
	defer tree.Squash()
	assert.NoError(b, tree.Populate())
	assert.NoError(b, tree.PopulateN(1024*1024*500, 5))

	names := lists.NewFileList().ListDir(tree.CWD)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StartTimer()
		m, err := model.New(tree.CWD, false, 1024*1024, 16)
		assert.NoError(b, err)
		lx, err := m.FeedManifests(true, true, true, names...)
		b.StopTimer()
		assert.NoError(b, err)
		for _, man := range lx {
			b.SetBytes(man.Size)
		}
	}
}
예제 #10
0
func Test_Storage_Upload_FinishUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("finish-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/finish-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/finish-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/finish-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)

	toUpload := mans.GetChunkLinkSlice(missing)

	for _, v := range toUpload {
		r, err := os.Open(tree.BlobFilename(v.Name))
		assert.NoError(t, err)
		defer r.Close()

		buf := make([]byte, v.Size)
		_, err = r.ReadAt(buf, v.Offset)

		err = stor.UploadChunk(*uID, v.Chunk.ID, bytes.NewReader(buf))
		assert.NoError(t, err)
	}

	err = stor.FinishUploadSession(*uID)
	assert.NoError(t, err)
}
예제 #11
0
func Test_Storage_Upload_CreateUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("create-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/create-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/create-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/create-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)
	assert.Len(t, missing, 4)
}
예제 #12
0
파일: git_test.go 프로젝트: pombredanne/bar
func Test_Git_Divert1(t *testing.T) {

	tree := fixtures.NewTree("Git_divert", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	g, err := gitFixture(tree)
	assert.NoError(t, err)

	//	logx.SetLevel(logx.TRACE)

	// get blobmap for further checks
	mod, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	names := lists.NewFileList().ListDir(tree.CWD)
	mans1, err := mod.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)

	// Run divert on "in-other" and "one"
	divert := git.NewDivert(g)
	spec, err := divert.PrepareBegin("other", "in-other", "one", "two/file-four with spaces.bin")
	assert.NoError(t, err)
	err = divert.Begin(spec)
	assert.NoError(t, err)

	// Make two blobs and collect their manifests
	bn1 := filepath.Join(tree.CWD, "in-other", "blob.bin")
	bn2 := filepath.Join(tree.CWD, "one", "file-one.bin")
	fixtures.MakeNamedBLOB(bn1, 110)
	fixtures.MakeNamedBLOB(bn2, 200)

	oMan1, err := fixtures.NewShadowFromFile(bn1)
	assert.NoError(t, err)
	oMan2, err := fixtures.NewShadowFromFile(bn2)
	assert.NoError(t, err)

	// commit
	spec1, err := divert.ReadSpec()
	assert.NoError(t, err)

	err = divert.Commit(spec1, "from-master")
	assert.NoError(t, err)

	err = divert.Cleanup(spec1)
	assert.NoError(t, err)

	err = divert.CleanSpec()
	assert.NoError(t, err)

	// Final checks
	branch, _, err := g.GetBranches()
	assert.NoError(t, err)
	assert.Equal(t, "master", branch)

	// check master files
	names = lists.NewFileList().ListDir(tree.CWD)
	mans2, err := mod.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)
	assert.EqualValues(t, mans1, mans2)

	// check stored branch
	err = g.Checkout("other")
	assert.NoError(t, err)

	oMan1p, err := fixtures.NewShadowFromFile(bn1)
	assert.NoError(t, err)
	assert.EqualValues(t, oMan1, oMan1p)

	oMan2p, err := fixtures.NewShadowFromFile(bn2)
	assert.NoError(t, err)
	assert.EqualValues(t, oMan2, oMan2p)
}