Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions internal/db/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ const (

func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
// Build test command
if len(testFiles) == 0 {
testFiles = append(testFiles, utils.DbTestsDir)
}
binds := make([]string, len(testFiles))
cmd := []string{"pg_prove", "--ext", ".pg", "--ext", ".sql", "-r"}
for _, fp := range testFiles {
relPath, err := filepath.Rel(utils.DbTestsDir, fp)
if err != nil {
return errors.Errorf("failed to resolve relative path: %w", err)
for i, fp := range testFiles {
if !filepath.IsAbs(fp) {
fp = filepath.Join(utils.CurrentDirAbs, fp)
}
cmd = append(cmd, relPath)
dockerPath := utils.ToDockerPath(fp)
cmd = append(cmd, dockerPath)
binds[i] = fmt.Sprintf("%s:%s:ro", fp, dockerPath)
}
if viper.GetBool("DEBUG") {
cmd = append(cmd, "--verbose")
}
// Mount tests directory into container as working directory
srcPath, err := filepath.Abs(utils.DbTestsDir)
if err != nil {
return errors.Errorf("failed to resolve absolute path: %w", err)
}
dstPath := "/tmp"
binds := []string{fmt.Sprintf("%s:%s:ro", srcPath, dstPath)}
// Enable pgTAP if not already exists
alreadyExists := false
options = append(options, func(cc *pgx.ConnConfig) {
Expand Down Expand Up @@ -87,8 +85,7 @@ func Run(ctx context.Context, testFiles []string, config pgconn.Config, fsys afe
"PGPASSWORD=" + config.Password,
"PGDATABASE=" + config.Database,
},
Cmd: cmd,
WorkingDir: dstPath,
Cmd: cmd,
},
hostConfig,
network.NetworkingConfig{},
Expand Down
Loading