()
| 13 | ) |
| 14 | |
| 15 | func main() { |
| 16 | var customPath string |
| 17 | var cachePath string |
| 18 | flag.StringVar(&customPath, "path", "", "Optional custom path for postgres data directory") |
| 19 | flag.StringVar(&cachePath, "cache", "", "Optional custom path for embedded postgres binaries") |
| 20 | flag.Parse() |
| 21 | |
| 22 | postgresPath := filepath.Join(os.TempDir(), "coder-test-postgres") |
| 23 | if customPath != "" { |
| 24 | postgresPath = customPath |
| 25 | } |
| 26 | if err := os.MkdirAll(postgresPath, os.ModePerm); err != nil { |
| 27 | log.Fatalf("Failed to create directory %s: %v", postgresPath, err) |
| 28 | } |
| 29 | if cachePath == "" { |
| 30 | cachePath = filepath.Join(postgresPath, "cache") |
| 31 | } |
| 32 | if err := os.MkdirAll(cachePath, os.ModePerm); err != nil { |
| 33 | log.Fatalf("Failed to create directory %s: %v", cachePath, err) |
| 34 | } |
| 35 | |
| 36 | ep := embeddedpostgres.NewDatabase( |
| 37 | embeddedpostgres.DefaultConfig(). |
| 38 | Version(embeddedpostgres.V16). |
| 39 | BinariesPath(filepath.Join(postgresPath, "bin")). |
| 40 | BinaryRepositoryURL("https://repo.maven.apache.org/maven2"). |
| 41 | DataPath(filepath.Join(postgresPath, "data")). |
| 42 | RuntimePath(filepath.Join(postgresPath, "runtime")). |
| 43 | CachePath(cachePath). |
| 44 | Username("postgres"). |
| 45 | Password("postgres"). |
| 46 | Database("postgres"). |
| 47 | Encoding("UTF8"). |
| 48 | Port(uint32(5432)). |
| 49 | Logger(os.Stdout), |
| 50 | ) |
| 51 | err := ep.Start() |
| 52 | if err != nil { |
| 53 | log.Fatalf("Failed to start embedded postgres: %v", err) |
| 54 | } |
| 55 | |
| 56 | // Troubleshooting: list files in cachePath |
| 57 | if err := filepath.Walk(cachePath, func(path string, info os.FileInfo, err error) error { |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | switch { |
| 62 | case info.IsDir(): |
| 63 | log.Printf("D: %s", path) |
| 64 | case info.Mode().IsRegular(): |
| 65 | log.Printf("F: %s [%s] (%d bytes) %s", path, info.Mode().String(), info.Size(), info.ModTime().Format(time.RFC3339)) |
| 66 | default: |
| 67 | log.Printf("Other: %s [%s] %s", path, info.Mode(), info.ModTime().Format(time.RFC3339)) |
| 68 | } |
| 69 | return nil |
| 70 | }); err != nil { |
| 71 | log.Printf("Failed to list files in cachePath %s: %v", cachePath, err) |
| 72 | } |
nothing calls this directly
no test coverage detected