Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
murfffi committed May 10, 2024
1 parent d297996 commit 21b334d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
71 changes: 33 additions & 38 deletions drivers/drivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ var (
DockerPort: "8080/tcp",
},
"csvq": {
DSN: "csvq://" + os.TempDir(),
// go test sets working directory to current package regardless of initial working directory
DSN: "csvq://./testdata/csvq",
},
}
cleanup bool
Expand Down Expand Up @@ -147,31 +148,7 @@ func TestMain(m *testing.M) {
}

for dbName, db := range dbs {
dsn := db.DSN
var hostPort string
if db.RunOptions != nil {
var ok bool
db.Resource, ok = pool.ContainerByName(db.RunOptions.Name)
if ok && !db.Resource.Container.State.Running {
err = db.Resource.Close()
if err != nil {
log.Fatalf("Could clean up stale container %s: %s", dbName, err)
}
ok = false
}
if !ok {
buildOpts := &dt.BuildOptions{
ContextDir: "./testdata/docker",
BuildArgs: db.BuildArgs,
}
db.Resource, err = pool.BuildAndRunWithBuildOptions(buildOpts, db.RunOptions)
if err != nil {
log.Fatalf("Could not start %s: %s", dbName, err)
}
}
hostPort = db.Resource.GetPort(db.DockerPort)
dsn = fmt.Sprintf(db.DSN, hostPort)
}
dsn, hostPort := getConnInfo(dbName, db, pool)
db.URL, err = dburl.Parse(dsn)
if err != nil {
log.Fatalf("Failed to parse %s URL %s: %v", dbName, db.DSN, err)
Expand Down Expand Up @@ -234,6 +211,35 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func getConnInfo(dbName string, db *Database, pool *dt.Pool) (string, string) {
if db.RunOptions == nil {
return db.DSN, ""
}

var ok bool
db.Resource, ok = pool.ContainerByName(db.RunOptions.Name)
if ok && !db.Resource.Container.State.Running {
err := db.Resource.Close()
if err != nil {
log.Fatalf("Failed to clean up stale container %s: %s", dbName, err)
}
ok = false
}
if !ok {
buildOpts := &dt.BuildOptions{
ContextDir: "./testdata/docker",
BuildArgs: db.BuildArgs,
}
var err error
db.Resource, err = pool.BuildAndRunWithBuildOptions(buildOpts, db.RunOptions)
if err != nil {
log.Fatalf("Failed to start %s: %s", dbName, err)
}
}
hostPort := db.Resource.GetPort(db.DockerPort)
return fmt.Sprintf(db.DSN, hostPort), hostPort
}

func TestWriter(t *testing.T) {
type testFunc struct {
label string
Expand Down Expand Up @@ -490,18 +496,7 @@ func TestCopy(t *testing.T) {
{
dbName: "csvq",
setupQueries: []setupQuery{
{query: "DROP TABLE IF EXISTS staff_copy"},
{query: `
CREATE TABLE IF NOT EXISTS staff_copy (
first_name,
last_name,
address_id,
email,
store_id,
active,
username,
password,
last_update);`, check: true},
{query: "CREATE TABLE IF NOT EXISTS staff_copy AS SELECT * FROM `staff.csv` WHERE 0=1", check: true},
},
src: "select first_name, last_name, address_id, email, store_id, active, username, password, last_update from staff",
dest: "staff_copy",
Expand Down
1 change: 1 addition & 0 deletions drivers/testdata/csvq/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*_copy
2 changes: 2 additions & 0 deletions drivers/testdata/csvq/staff.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
first_name,last_name,address_id,email,store_id,active,username,password,last_update
John,Doe,1,[email protected],1,true,jdoe,abc,2024-05-10T08:12:05.46875Z

0 comments on commit 21b334d

Please sign in to comment.