mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-27 03:09:14 -06:00
Merge pull request #493 from aboodman/counter-test
counter: add a unit test
This commit is contained in:
@@ -9,8 +9,11 @@ import (
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var (
|
||||
dsFlags = dataset.NewFlags()
|
||||
)
|
||||
|
||||
func main() {
|
||||
dsFlags := dataset.NewFlags()
|
||||
flag.Parse()
|
||||
|
||||
ds := dsFlags.CreateDataset()
|
||||
|
||||
35
clients/counter/counter_test.go
Normal file
35
clients/counter/counter_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
)
|
||||
|
||||
var (
|
||||
dir string
|
||||
ldb string
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "nomstest")
|
||||
d.Chk.NoError(err)
|
||||
ldb = path.Join(dir, "ldb")
|
||||
|
||||
defer d.Chk.NoError(os.RemoveAll(dir))
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestCounter(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
args := []string{"counter", "-ldb", ldb, "-ds", "counter"}
|
||||
assert.Equal("1\n", util.Run(main, args))
|
||||
assert.Equal("2\n", util.Run(main, args))
|
||||
assert.Equal("3\n", util.Run(main, args))
|
||||
}
|
||||
33
clients/util/run.go
Normal file
33
clients/util/run.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/attic-labs/noms/d"
|
||||
)
|
||||
|
||||
func Run(f func(), args []string) string {
|
||||
origArgs := os.Args
|
||||
origOut := os.Stdout
|
||||
out, err := ioutil.TempFile(os.TempDir(), "")
|
||||
|
||||
defer func() {
|
||||
os.Args = origArgs
|
||||
os.Stdout = origOut
|
||||
out.Close()
|
||||
d.Chk.NoError(os.Remove(out.Name()))
|
||||
}()
|
||||
|
||||
d.Chk.NoError(err)
|
||||
|
||||
os.Args = args
|
||||
os.Stdout = out
|
||||
f()
|
||||
|
||||
_, err = os.Stdout.Seek(0, 0)
|
||||
d.Chk.NoError(err)
|
||||
b, err := ioutil.ReadAll(os.Stdout)
|
||||
d.Chk.NoError(err)
|
||||
return string(b)
|
||||
}
|
||||
Reference in New Issue
Block a user