diff --git a/internal/db/test/test.go b/internal/db/test/test.go index 428fc61a9..3f9aff8e6 100644 --- a/internal/db/test/test.go +++ b/internal/db/test/test.go @@ -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) { @@ -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{},