Skip to content

Commit

Permalink
feat(spantest): support multiple schema globs
Browse files Browse the repository at this point in the history
When combining schemas from multiple sources.
  • Loading branch information
odsod committed Apr 26, 2021
1 parent 49de79a commit 46f5798
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions spantest/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ func (fx *EmulatorFixture) Context() context.Context {
}

// NewDatabaseFromDDLFiles creates a new database with a random ID from the provided DDL file path glob.
func (fx *EmulatorFixture) NewDatabaseFromDDLFiles(t *testing.T, glob string) *spanner.Client {
func (fx *EmulatorFixture) NewDatabaseFromDDLFiles(t *testing.T, globs ...string) *spanner.Client {
t.Helper()
files, err := filepath.Glob(glob)
assert.NilError(t, err)
var files []string
for _, glob := range globs {
globFiles, err := filepath.Glob(glob)
assert.NilError(t, err)
files = append(files, globFiles...)
}
var statements []string
for _, file := range files {
content, err := ioutil.ReadFile(file)
Expand Down
2 changes: 1 addition & 1 deletion spantest/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// Fixture is a Spanner test fixture.
type Fixture interface {
// NewDatabaseFromDLLFiles creates a new database and applies the DDL files from the provided glob.
NewDatabaseFromDDLFiles(t *testing.T, glob string) *spanner.Client
NewDatabaseFromDDLFiles(t *testing.T, globs ...string) *spanner.Client
// NewDatabaseFromStatements creates a new database and applies the provided DLL statements.
NewDatabaseFromStatements(t *testing.T, statements []string) *spanner.Client
}
10 changes: 7 additions & 3 deletions spantest/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ func NewInMemoryFixture(t *testing.T) Fixture {
}

// NewDatabaseFromDDLFiles implements Fixture.
func (fx *InMemoryFixture) NewDatabaseFromDDLFiles(t *testing.T, glob string) *spanner.Client {
func (fx *InMemoryFixture) NewDatabaseFromDDLFiles(t *testing.T, globs ...string) *spanner.Client {
t.Helper()
files, err := filepath.Glob(glob)
assert.NilError(t, err)
var files []string
for _, glob := range globs {
globFiles, err := filepath.Glob(glob)
assert.NilError(t, err)
files = append(files, globFiles...)
}
var statements []string
for _, file := range files {
content, err := ioutil.ReadFile(file)
Expand Down

0 comments on commit 46f5798

Please sign in to comment.