mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-08 02:36:27 -05:00
Pull from one ChunkStore to another
This initial implementation requires that both the "remote" and local ChunkStores be accessible by the machine running the pull command. I took an initial pass at splitting up the functions so that, e.g., calculating which refs are needed could be done on an actual remote machine, and we can add a chunk copying routine that gets data from the network or something. Towards issue #81
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
"github.com/attic-labs/noms/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createTestDataset(name string) dataset.Dataset {
|
||||
var t chunks.ChunkStore = &chunks.TestStore{}
|
||||
return dataset.NewDataset(datas.NewDataStore(t, t.(chunks.RootTracker)), name)
|
||||
|
||||
}
|
||||
|
||||
func TestValidateRef(t *testing.T) {
|
||||
cs := &chunks.TestStore{}
|
||||
r, err := types.WriteValue(types.Bool(true), cs)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = validateRefAsSetOfCommit(r, cs)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestPull(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
puller := createTestDataset("puller")
|
||||
pullee := createTestDataset("pullee")
|
||||
|
||||
commitValue := func(v types.Value, ds dataset.Dataset) dataset.Dataset {
|
||||
return ds.Commit(
|
||||
datas.NewSetOfCommit().Insert(
|
||||
datas.NewCommit().SetParents(ds.Heads().NomsValue()).SetValue(v)))
|
||||
}
|
||||
|
||||
initialValue := types.NewMap(
|
||||
types.NewString("first"), types.NewList(),
|
||||
types.NewString("second"), types.NewList(types.Int32(2)))
|
||||
|
||||
pullee = commitValue(initialValue, pullee)
|
||||
puller = commitValue(initialValue, puller)
|
||||
|
||||
updatedValue := initialValue.Set(
|
||||
types.NewString("third"), types.NewList(types.Int32(1)))
|
||||
|
||||
pullee = commitValue(updatedValue, pullee)
|
||||
|
||||
refs, err := DiffHeadsByRef(puller.Heads().Ref(), pullee.Heads().Ref(), pullee)
|
||||
assert.NoError(err)
|
||||
assert.NoError(CopyChunks(refs, pullee, puller))
|
||||
puller, err = SetNewHeads(pullee.Heads().Ref(), puller)
|
||||
assert.NoError(err)
|
||||
assert.Equal(pullee.Heads().Ref(), puller.Heads().Ref())
|
||||
assert.True(pullee.Heads().Equals(puller.Heads()))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user