1
0
mirror of https://github.com/xorcare/testing-go-code-with-postgres.git synced 2025-06-30 23:23:40 +02:00

Rename function for isolated database connection

Other ways to clean the database in tests will be added soon, so the
tests are being moved to a separate file.
This commit is contained in:
Vasiliy Vasilyuk
2024-06-30 22:53:05 +03:00
parent 83b2f61e41
commit 13e3596692
5 changed files with 108 additions and 99 deletions

View File

@ -31,7 +31,7 @@ type TestingT interface {
Failed() bool
}
func New(t TestingT) *Postgres {
func NewWithIsolatedDatabase(t TestingT) *Postgres {
return newPostgres(t).cloneFromReference()
}

View File

@ -25,7 +25,7 @@ func TestNewPostgres(t *testing.T) {
t.Parallel()
// Arrange
postgres := testingpg.New(t)
postgres := testingpg.NewWithIsolatedDatabase(t)
ctx := context.Background()
dbPool, err := pgxpool.New(ctx, postgres.URL())
@ -45,7 +45,7 @@ func TestNewPostgres(t *testing.T) {
t.Parallel()
// Arrange
postgres := testingpg.New(t)
postgres := testingpg.NewWithIsolatedDatabase(t)
ctx := context.Background()
// Act
@ -63,8 +63,8 @@ func TestNewPostgres(t *testing.T) {
t.Parallel()
// Arrange
postgres1 := testingpg.New(t)
postgres2 := testingpg.New(t)
postgres1 := testingpg.NewWithIsolatedDatabase(t)
postgres2 := testingpg.NewWithIsolatedDatabase(t)
ctx := context.Background()
@ -82,8 +82,8 @@ func TestNewPostgres(t *testing.T) {
t.Parallel()
// Arrange
postgres1 := testingpg.New(t)
postgres2 := testingpg.New(t)
postgres1 := testingpg.NewWithIsolatedDatabase(t)
postgres2 := testingpg.NewWithIsolatedDatabase(t)
// Act
url1 := postgres1.URL()