fix: pgtest left an anonymous volume behind on every run

The postgres image declares a VOLUME, so tearing the container down with
`docker rm -f` (no -v) orphaned its anonymous data volume each time the
test binary ran. Add -v to all three teardown sites, and state the
cleanup expectation in AGENTS.md so a killed run gets swept by hand.
This commit is contained in:
2026-08-23 13:07:04 +07:00
parent 2ac1f0c507
commit ffda243c04
2 changed files with 14 additions and 3 deletions
+5 -3
View File
@@ -40,7 +40,9 @@ func Main(m *testing.M) int {
fmt.Println("pgtest:", err)
return 1
}
defer exec.Command("docker", "rm", "-f", id).Run()
// -v: the postgres image declares a VOLUME, so an explicit rm without it
// leaves the anonymous data volume behind on every test run.
defer exec.Command("docker", "rm", "-f", "-v", id).Run()
adminURL = url
return m.Run()
@@ -85,7 +87,7 @@ func start() (id, url string, err error) {
port, err := exec.Command("docker", "port", id, "5432/tcp").Output()
if err != nil {
exec.Command("docker", "rm", "-f", id).Run()
exec.Command("docker", "rm", "-f", "-v", id).Run()
return "", "", fmt.Errorf("docker port: %w", err)
}
// "0.0.0.0:32768" (and possibly a second, IPv6 line); the port is all we want.
@@ -94,7 +96,7 @@ func start() (id, url string, err error) {
first[strings.LastIndex(first, ":")+1:])
if err := waitReady(url); err != nil {
exec.Command("docker", "rm", "-f", id).Run()
exec.Command("docker", "rm", "-f", "-v", id).Run()
return "", "", err
}
return id, url, nil