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

29 Commits

Author SHA1 Message Date
536cbe330b Bump github.com/jackc/pgx/v5 to v5.5.2 2024-01-27 00:21:02 +03:00
942d210bb3 Bump github.com/google/uuid to v1.6.0 2024-01-27 00:20:46 +03:00
f8cba15b0d Add known issue with colima
This problem is caused by incorrect mounting of files.

```
/var/folders/3p/glp5vp4916n03wmjh_b0gf6m0000gn/T/tmp.ib2dU9TY
❯ git clone https://github.com/xorcare/testing-go-code-with-postgres
cd testing-go-code-with-postgres
make test-env-up test
Cloning into 'testing-go-code-with-postgres'...
remote: Enumerating objects: 124, done.
remote: Counting objects: 100% (66/66), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 124 (delta 36), reused 51 (delta 30), pack-reused 58
Receiving objects: 100% (124/124), 31.92 KiB | 4.56 MiB/s, done.
Resolving deltas: 100% (50/50), done.
[+] Building 0.0s (0/0)                                                              docker:default
[+] Running 2/0
 ✔ Container testing-go-code-with-postgres-postgres-1  Recreated                               0.0s
 ✔ Container testing-go-code-with-postgres-migrate-1   Recreated                               0.0s
Attaching to testing-go-code-with-postgres-migrate-1
dependency failed to start: container testing-go-code-with-postgres-postgres-1 exited (126)
make: *** [test-env-up] Error 1
```

```
/var/folders/3p/glp5vp4916n03wmjh_b0gf6m0000gn/T/tmp.ib2dU9TY/testing-go-code-with-postgres
❯ docker-compose up
[+] Building 0.0s (0/0)                                                              docker:default
[+] Running 1/0
 ✔ Container testing-go-code-with-postgres-postgres-1  Created                                 0.0s
Attaching to testing-go-code-with-postgres-migrate-1, testing-go-code-with-postgres-postgres-1
testing-go-code-with-postgres-postgres-1  | The files belonging to this database system will be owned by user "postgres".
testing-go-code-with-postgres-postgres-1  | This user must also own the server process.
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | The database cluster will be initialized with locale "en_US.utf8".
testing-go-code-with-postgres-postgres-1  | The default database encoding has accordingly been set to "UTF8".
testing-go-code-with-postgres-postgres-1  | The default text search configuration will be set to "english".
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | Data page checksums are disabled.
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | fixing permissions on existing directory /var/lib/postgresql/data ... ok
testing-go-code-with-postgres-postgres-1  | creating subdirectories ... ok
testing-go-code-with-postgres-postgres-1  | selecting dynamic shared memory implementation ... posix
testing-go-code-with-postgres-postgres-1  | selecting default max_connections ... 100
testing-go-code-with-postgres-postgres-1  | selecting default shared_buffers ... 128MB
testing-go-code-with-postgres-postgres-1  | selecting default time zone ... UTC
testing-go-code-with-postgres-postgres-1  | creating configuration files ... ok
testing-go-code-with-postgres-postgres-1  | running bootstrap script ... ok
testing-go-code-with-postgres-postgres-1  | sh: locale: not found
testing-go-code-with-postgres-postgres-1  | 2023-11-18 13:34:16.419 UTC [31] WARNING:  no usable system locales were found
testing-go-code-with-postgres-postgres-1  | performing post-bootstrap initialization ... ok
testing-go-code-with-postgres-postgres-1  | syncing data to disk ... ok
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | Success. You can now start the database server using:
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | initdb: warning: enabling "trust" authentication for local connections
testing-go-code-with-postgres-postgres-1  | initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
testing-go-code-with-postgres-postgres-1  | waiting for server to start....2023-11-18 13:34:16.617 UTC [37] LOG:  starting PostgreSQL 15.3 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924, 64-bit
testing-go-code-with-postgres-postgres-1  | 2023-11-18 13:34:16.619 UTC [37] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
testing-go-code-with-postgres-postgres-1  | 2023-11-18 13:34:16.620 UTC [40] LOG:  database system was shut down at 2023-11-18 13:34:16 UTC
testing-go-code-with-postgres-postgres-1  | 2023-11-18 13:34:16.622 UTC [37] LOG:  database system is ready to accept connections
testing-go-code-with-postgres-postgres-1  |  done
testing-go-code-with-postgres-postgres-1  | server started
testing-go-code-with-postgres-postgres-1  |
testing-go-code-with-postgres-postgres-1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/docker-multiple-databases.sh
testing-go-code-with-postgres-postgres-1  | /usr/local/bin/docker-entrypoint.sh: line 170: /docker-entrypoint-initdb.d/docker-multiple-databases.sh: Is a directory
testing-go-code-with-postgres-postgres-1 exited with code 126
dependency failed to start: container testing-go-code-with-postgres-postgres-1 exited (126)
```
2023-11-18 16:36:40 +03:00
ef4031f027 Allow running pipelines without merge request
This will allow me to pass CI checks without creating merge requests,
since I work alone there is no point in them.
2023-11-15 22:23:35 +03:00
ab5f864a78 Enable linter 'testpackage'
This will avoid testing private functions and methods.
2023-11-14 22:35:32 +03:00
b17c6166dd Enable linter 'testifylint'
This will allow to avoid mistakes.
2023-11-14 22:35:32 +03:00
0339ceb25b Bump golangci-lint to v1.55.2 2023-11-14 22:35:25 +03:00
8c686cca5c Hide sample test titles with a spoiler 2023-11-14 21:29:32 +03:00
c41bbafb59 Add 'Quick start' to README.md 2023-11-14 21:26:04 +03:00
942c43a636 Replace 'Dash' with 'Hyphen'
That's a more correct title.
2023-10-11 20:26:28 +03:00
31d6570cd7 Fix command for teardown test env in GitHub Actions 2023-10-05 17:51:26 +03:00
e9de025f7e Migrate to Compose V2
From July 2023 Compose V1 stopped receiving updates. It’s also no
longer available in new releases of Docker Desktop.

Compose V2, which was first released in 2020, is included with all
currently supported versions of Docker Desktop. It offers an improved
CLI experience, improved build performance with BuildKit, and continued
new-feature development.

See https://docs.docker.com/compose/migrate
See https://docs.docker.com/compose/reference
2023-09-22 22:16:15 +03:00
d697a4bcc7 Make return the exit code of a 'migrate' service container
This will make it easier to debug problems, because if an error occurs,
it returns from docker-compose and interrupts the chain of commands,
for example:

make test-env-down test-env-up test
2023-08-20 16:46:23 +03:00
b98187650e Make human-readable database name
Sometimes tests terminate fatally and databases are not deleted and you
want to understand which test left garbage behind. It is also in the
future it will be possible to add the ability not to delete databases
for tests that ended with an error, and it will be necessary to
understand from which test the database.

Therefore, the generation of the database name from the name of the
test with the addition of a unique identifier so that the names do not
overlap.

    Reports the maximum identifier length. It is determined as one less
    than the value of NAMEDATALEN when building the server. The default
    value of NAMEDATALEN is 64; therefore the default
    max_identifier_length is 63 bytes, which can be less than 63
    characters when using multibyte encodings.

See https://www.postgresql.org/docs/15/runtime-config-preset.html

    PostgreSQL allows you to create any number of databases at a given
    site. Database names must have an alphabetic first character and
    are limited to 63 bytes in length. A convenient choice is to create
    a database with the same name as your current user name. Many tools
    assume that database name as the default, so it can save you some
    typing. To create that database, simply type:

See https://www.postgresql.org/docs/15/tutorial-createdb.html
2023-07-16 17:18:30 +03:00
cdd90f86db Fix placeholder for the database template name
When a template database name contains invalid characters such as `-`,
the request to create a new database stops working.

To reduce this behavior, quotation marks have been added.
2023-07-15 20:34:41 +03:00
c7a32b73ea Speed up your integration tests by one line 2023-07-14 17:46:23 +03:00
7613653f39 Add set of small fixes to testingpg package
Added some set of disparate improvements, to improve readability.
2023-07-13 21:24:03 +03:00
1957a32dcb Increase the maximum number of connections
This is to simplify testing using the `-count=100` option.
2023-07-12 22:40:49 +03:00
59c4d2e3e1 Make a singleton for *pgxpool.Pool
This should reduce the number of parasitic connection reopenings.
2023-07-12 22:40:44 +03:00
4bb736475b Make a lazy loading for opening a connection
In the current approach, the connection logic is only triggered at the
moment of immediate need for connection.

We also get a single connection opening point.
2023-07-12 22:17:11 +03:00
c2e0810c2c Update README.md 2023-07-11 23:15:26 +03:00
42815eab15 Add GitLab CI and mirroring to GitLab
Added an example .gitlab-ci.yml, to make a sample more informative.

Also added mirroring to gitlab to simplify repository development and
gitlab ci validation.
2023-07-11 22:53:23 +03:00
5fc60fb2f5 Add coverage report by Codecov
This is needed to display coverage, and as an example of setting up
coverage counts.

Also, added badges to make the repositories look prettier.
2023-07-10 23:36:05 +03:00
cfe9add3d7 Add lint to CI
It is necessary to remember not to bring the code to a state complying
with the rules.
2023-07-10 23:10:36 +03:00
f5f4e2ce8c Add GitHub actions workflow
This is necessary for the completeness of the example.
2023-07-10 22:52:46 +03:00
9cb6ced6ef Add parallel running for tests 2023-07-05 07:57:37 +03:00
fd50c57aff Mark tests as integration
It is necessary so that these tests will not run when using the
`make test-short` command.
2023-07-05 07:51:30 +03:00
b346272f7f Publish an example testing go code with Postgres 2023-07-05 01:31:59 +03:00
7e6770223e Initial commit 2023-06-17 16:29:50 +03:00