shove: Add a unit test

This commit is contained in:
Aaron Boodman
2015-10-28 17:22:53 -07:00
parent 7d325acb2f
commit 12c63649f2
2 changed files with 50 additions and 10 deletions
+38
View File
@@ -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()))
}
+12 -10
View File
@@ -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)