Skip to content

Commit 79ec22f

Browse files
authored
fix(db): set working directory for SQL relative imports (#4740)
2 parents 6865225 + 0ecc36e commit 79ec22f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/db/test/test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
_ "embed"
66
"fmt"
77
"os"
8+
"path"
89
"path/filepath"
910

1011
"github.com/docker/docker/api/types/container"
@@ -35,13 +36,20 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe
3536
}
3637
binds := make([]string, len(testFiles))
3738
cmd := []string{"pg_prove", "--ext", ".pg", "--ext", ".sql", "-r"}
39+
var workingDir string
3840
for i, fp := range testFiles {
3941
if !filepath.IsAbs(fp) {
4042
fp = filepath.Join(utils.CurrentDirAbs, fp)
4143
}
4244
dockerPath := utils.ToDockerPath(fp)
4345
cmd = append(cmd, dockerPath)
4446
binds[i] = fmt.Sprintf("%s:%s:ro", fp, dockerPath)
47+
if workingDir == "" {
48+
workingDir = dockerPath
49+
if path.Ext(dockerPath) != "" {
50+
workingDir = path.Dir(dockerPath)
51+
}
52+
}
4553
}
4654
if viper.GetBool("DEBUG") {
4755
cmd = append(cmd, "--verbose")
@@ -89,7 +97,8 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe
8997
"PGPASSWORD=" + config.Password,
9098
"PGDATABASE=" + config.Database,
9199
},
92-
Cmd: cmd,
100+
Cmd: cmd,
101+
WorkingDir: workingDir,
93102
},
94103
hostConfig,
95104
network.NetworkingConfig{},

0 commit comments

Comments
 (0)