mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-25 03:34:05 -05:00
shove: Add a unit test
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/suite"
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
func TestShove(t *testing.T) {
|
||||
suite.Run(t, &testSuite{})
|
||||
}
|
||||
|
||||
type testSuite struct {
|
||||
util.ClientTestSuite
|
||||
}
|
||||
|
||||
func (s *testSuite) TestShove() {
|
||||
s.LdbFlagName = "-source-ldb"
|
||||
cs := chunks.NewLevelDBStore(s.LdbDir, 1, false)
|
||||
ds := dataset.NewDataset(datas.NewDataStore(cs), "foo")
|
||||
ds, ok := ds.Commit(types.Int32(42))
|
||||
s.True(ok)
|
||||
ds.Close()
|
||||
|
||||
ldb2dir := path.Join(s.TempDir, "ldb2")
|
||||
out := s.Run(main, []string{"-source-ds", "foo", "-sink-ldb", ldb2dir, "-sink-ds", "bar"})
|
||||
s.Equal("", out)
|
||||
|
||||
cs2 := chunks.NewLevelDBStore(ldb2dir, 1, false)
|
||||
ds2 := dataset.NewDataset(datas.NewDataStore(cs2), "bar")
|
||||
s.True(types.Int32(42).Equals(ds2.Head().Value()))
|
||||
}
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
|
||||
type ClientTestSuite struct {
|
||||
suite.Suite
|
||||
TempDir string
|
||||
LdbDir string
|
||||
out *os.File
|
||||
LdbFlagName string
|
||||
TempDir string
|
||||
LdbDir string
|
||||
out *os.File
|
||||
}
|
||||
|
||||
func (suite *ClientTestSuite) SetupSuite() {
|
||||
@@ -37,13 +38,14 @@ func (suite *ClientTestSuite) Run(m func(), args []string) string {
|
||||
origOut := os.Stdout
|
||||
origErr := os.Stderr
|
||||
|
||||
os.Args = append([]string{"testcmd", "-ldb", suite.LdbDir}, args...)
|
||||
os.Stdout = suite.out
|
||||
ldbFlagName := suite.LdbFlagName
|
||||
|
||||
// TODO: If some tests need this, we can return it as a separate out param. But more convenient to swallow it until then.
|
||||
devnull, err := os.Open(os.DevNull)
|
||||
d.Chk.NoError(err)
|
||||
os.Stderr = devnull
|
||||
if ldbFlagName == "" {
|
||||
ldbFlagName = "-ldb"
|
||||
}
|
||||
|
||||
os.Args = append([]string{"cmd", ldbFlagName, suite.LdbDir}, args...)
|
||||
os.Stdout = suite.out
|
||||
|
||||
defer func() {
|
||||
os.Args = origArgs
|
||||
@@ -53,7 +55,7 @@ func (suite *ClientTestSuite) Run(m func(), args []string) string {
|
||||
|
||||
m()
|
||||
|
||||
_, err = suite.out.Seek(0, 0)
|
||||
_, err := suite.out.Seek(0, 0)
|
||||
d.Chk.NoError(err)
|
||||
b, err := ioutil.ReadAll(os.Stdout)
|
||||
d.Chk.NoError(err)
|
||||
|
||||
Reference in New Issue
Block a user