|
2 | 2 |
|
3 | 3 | [](https://godoc.org/github.com/olomix/go-test-pg) |
4 | 4 |
|
5 | | -v2 version depends on pgx/v5. If you want support for pgx/v4, use 1.x.x |
6 | | -version of this package. |
| 5 | +v2 depends on pgx/v5. For pgx/v4 support, use the 1.x.x version of this |
| 6 | +package. |
7 | 7 |
|
8 | | -The aim this package is to help test golang programs against PostgreSQL |
9 | | -database. It creates an empty database for each test and drops it when test |
10 | | -is complete. |
| 8 | +This package helps test Go programs against a PostgreSQL database. It |
| 9 | +creates a fresh database for each test and drops it when the test completes. |
11 | 10 |
|
12 | | -As a side effect tool checks that all resources are released when test exits. |
13 | | -If any Rows is not closed or Conn is not released to pool, test fails. |
| 11 | +The tool also checks that all resources are released when the test exits. |
| 12 | +If any `Rows` are not closed or a `Conn` is not released to the pool, the |
| 13 | +test fails. |
14 | 14 |
|
15 | | -`go-test-pg` uses schema file to initialize database with. It creates |
16 | | -template database with this schema. Then each temporary database for every test |
17 | | -creates from this template database. If the template database for this |
18 | | -schema is exists, it will be reused. The name of the template database |
19 | | -is composed of `baseName` and md5 hashsum of schema file content. If schema file |
20 | | -is empty, then use default PostgreSQL empty database `template1`. |
| 15 | +`go-test-pg` uses a schema file to set up the database. It creates a |
| 16 | +template database from this schema, and each test gets its own copy of |
| 17 | +that template. If a template database for the schema already exists, it |
| 18 | +is reused. The template name is composed of `baseName` and the MD5 hash |
| 19 | +of the schema file content. If no schema file is provided, the default |
| 20 | +PostgreSQL `template1` database is used. |
21 | 21 |
|
22 | | -On complete, temporary databases would be dropped, template database will not |
23 | | -be dropped and would remain for future reuse. |
| 22 | +When a test completes, its temporary database is dropped. The template |
| 23 | +database is kept for future reuse. |
24 | 24 |
|
25 | | -Template database would be created only on first use. If you call `NewPool` |
26 | | -and do not call `With<something>` on it, real database would not be touched. |
| 25 | +The template database is created on first use. If you create a `Pgpool` |
| 26 | +but never call any `With*` method, no database is touched. |
27 | 27 |
|
28 | | -Each method was `Std` version that returns `*sql.DB`. For example, |
29 | | -default method `WithFixtures` returns `*pgxpool.Pool` and `WithStdFixtures` |
30 | | -returns `*sql.DB`. |
| 28 | +Each method has a `Std` variant that returns `*sql.DB`. For example, |
| 29 | +`WithFixtures` returns `*pgxpool.Pool` and `WithStdFixtures` returns |
| 30 | +`*sql.DB`. |
31 | 31 |
|
32 | 32 | ## Example usage |
33 | 33 |
|
@@ -57,12 +57,11 @@ func TestX(t *testing.T) { |
57 | 57 | } |
58 | 58 | ``` |
59 | 59 |
|
60 | | -Connection to database configured using standard PostgreSQL environment |
61 | | -variable https://www.postgresql.org/docs/11/libpq-envars.html. User needs |
62 | | -permissions to create databases. |
| 60 | +The database connection is configured using standard PostgreSQL environment |
| 61 | +variables (https://www.postgresql.org/docs/11/libpq-envars.html). The user |
| 62 | +needs permissions to create databases. |
63 | 63 |
|
64 | | -If you want to skip all database tests, you need to set `Skip` field in Pgpool |
65 | | -struct to `true`. |
| 64 | +To skip all database tests, set `Skip` to `true`: |
66 | 65 |
|
67 | 66 | ```go |
68 | 67 | var dbpool = &ptg.Pgpool{Skip: true} |
|
0 commit comments