-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement adapter Name and add Name constant (#65)
* Implement adapter Name and add Name constant * Update go-rel dependencies * Update primaryreplica dependnecy * Update to allow to use Open and MustOpen for pgx driver * Update supported postgres versions to match official supported postgres server versions * Do not run tests in parallel to not mess up pgx/postgres drivers * Fix review comment
- Loading branch information
Showing
8 changed files
with
100 additions
and
298 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
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 |
---|---|---|
@@ -1,63 +1,57 @@ | ||
package postgres | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-rel/rel" | ||
"github.com/jackc/pgx/v4" | ||
"github.com/jackc/pgx/v4/stdlib" | ||
"github.com/stretchr/testify/assert" | ||
|
||
_ "github.com/jackc/pgx/v5/stdlib" | ||
) | ||
|
||
func init() { | ||
// hack to make sure location it has the same location object as returned by pq driver. | ||
// hack to make sure location it has the same location object as returned by pgx driver. | ||
time.Local, _ = time.LoadLocation("Asia/Jakarta") | ||
} | ||
|
||
func pgxOpen(dsn string) (rel.Adapter, error) { | ||
config, err := pgx.ParseConfig(dsn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
database, err := sql.Open("pgx", stdlib.RegisterConnConfig(config)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return New(database), err | ||
} | ||
|
||
func TestAdapterPgx_specs(t *testing.T) { | ||
adapter, err := pgxOpen(dsn()) | ||
assert.Nil(t, err) | ||
driverName = "pgx" | ||
adapter := MustOpen(dsn()) | ||
defer adapter.Close() | ||
|
||
repo := rel.New(adapter) | ||
AdapterSpecs(t, repo) | ||
} | ||
|
||
func TestAdapterPgx_Transaction_commitError(t *testing.T) { | ||
adapter, err := pgxOpen(dsn()) | ||
assert.Nil(t, err) | ||
driverName = "pgx" | ||
adapter := MustOpen(dsn()) | ||
defer adapter.Close() | ||
|
||
assert.NotNil(t, adapter.Commit(ctx)) | ||
} | ||
|
||
func TestAdapterPgx_Transaction_rollbackError(t *testing.T) { | ||
adapter, err := pgxOpen(dsn()) | ||
assert.Nil(t, err) | ||
driverName = "pgx" | ||
adapter := MustOpen(dsn()) | ||
defer adapter.Close() | ||
|
||
assert.NotNil(t, adapter.Rollback(ctx)) | ||
} | ||
|
||
func TestAdapterPgx_Exec_error(t *testing.T) { | ||
adapter, err := pgxOpen(dsn()) | ||
assert.Nil(t, err) | ||
driverName = "pgx" | ||
adapter := MustOpen(dsn()) | ||
defer adapter.Close() | ||
|
||
_, _, err = adapter.Exec(ctx, "error", nil) | ||
_, _, err := adapter.Exec(ctx, "error", nil) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestAdapterPgx_InvalidDriverPanic(t *testing.T) { | ||
assert.Panics(t, func() { | ||
driverName = "pgx/v4" | ||
MustOpen("postgres://test:test@localhost:1111/test?sslmode=disable&timezone=Asia/Jakarta") | ||
}) | ||
} |
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