-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(postgres): use faster sql.DB instead of docker exec psql for sn…
…apshot/restore [rebased for main] (#2600) * feat(postgres): use faster sql.DB instead of `docker exec psql` for creating & restoring snapshots * test(postgres): Make tests work reliably on slower computers * chore(postgres): simplify testdata Remove all commented lines * feat(postgres): add postgres.SQLDriverName for using go SQL drivers that don't register as "postgres" * test(postgres): Add test for snapshot fallback to docker-exec * docs(postgres): Update docs for wait strategies and custom SQL drivers * feat(postgres): expose postgres.BasicWaitStrategies * docs(postgres): include docs marker of release * chore(postgres): safeguard nil check * style: small comments from review * chore: convert SQLDriverName global into a container options * chore: update container struct for snapshotting --------- Co-authored-by: Manuel de la Peña <[email protected]>
- Loading branch information
1 parent
59cf064
commit 0d7ebaf
Showing
7 changed files
with
301 additions
and
746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package postgres | ||
|
||
import ( | ||
"github.com/testcontainers/testcontainers-go" | ||
) | ||
|
||
type options struct { | ||
// SQLDriverName is the name of the SQL driver to use. | ||
SQLDriverName string | ||
} | ||
|
||
func defaultOptions() options { | ||
return options{ | ||
SQLDriverName: "postgres", | ||
} | ||
} | ||
|
||
// Compiler check to ensure that Option implements the testcontainers.ContainerCustomizer interface. | ||
var _ testcontainers.ContainerCustomizer = (Option)(nil) | ||
|
||
// Option is an option for the Redpanda container. | ||
type Option func(*options) | ||
|
||
// Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface. | ||
func (o Option) Customize(*testcontainers.GenericContainerRequest) error { | ||
// NOOP to satisfy interface. | ||
return nil | ||
} | ||
|
||
// WithSQLDriver sets the SQL driver to use for the container. | ||
// It is passed to sql.Open() to connect to the database when making or restoring snapshots. | ||
// This can be set if your app imports a different postgres driver, f.ex. "pgx" | ||
func WithSQLDriver(driver string) Option { | ||
return func(o *options) { | ||
o.SQLDriverName = driver | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.