Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dstest): Cache the reading of TestCases, speeding up unit tests #141

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
go get -v -d -u
github.com/ipfs/go-datastore
github.com/jbenet/go-base58
github.com/jinzhu/copier
github.com/multiformats/go-multihash
github.com/qri-io/compare
github.com/datatogether/cdxj
Expand Down
12 changes: 12 additions & 0 deletions dstest/dstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"

"github.com/jinzhu/copier"
logger "github.com/ipfs/go-log"
"github.com/qri-io/cafs"
"github.com/qri-io/dataset"
Expand Down Expand Up @@ -51,6 +52,8 @@ type TestCase struct {
Expect *dataset.Dataset
}

var testCaseCache map[string]TestCase = make(map[string]TestCase)

// BodyFile creates a new in-memory file from data & filename properties
func (t TestCase) BodyFile() cafs.File {
return cafs.NewMemfileBytes(t.BodyFilename, t.Body)
Expand Down Expand Up @@ -105,6 +108,12 @@ func LoadTestCases(dir string) (tcs map[string]TestCase, err error) {
// dir should be the path to the directory to check, and any parsing errors will
// be logged using t.Log methods
func NewTestCaseFromDir(dir string) (tc TestCase, err error) {
if got, ok := testCaseCache[dir]; ok {
tc = TestCase{}
copier.Copy(&tc, &got)
return
}

tc = TestCase{
Path: dir,
Name: filepath.Base(dir),
Expand Down Expand Up @@ -148,6 +157,9 @@ func NewTestCaseFromDir(dir string) (tc TestCase, err error) {
}
err = nil

preserve := TestCase{}
copier.Copy(&preserve, &tc)
testCaseCache[dir] = preserve
return
}

Expand Down