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

Example of testing Go code with Postgres

Go workflow status badge codecov Gitlab CI Pipeline Gitlab CI Coverage Go Report Card

The example suggests a solution to the problem of cleaning the database after running tests and the problem of running tests in parallel. It also shows how to organize integration testing of Go code with Postgres.

What's interesting here?

Generating human-readable database names from t.Name() to simplifying problem investigation. The last 8 characters are a short unique identifier needed to prevent name collision, its necessary because the maximum length of the name is 63 bytes, and the name must be unique.

TestNewPostgres-Changes-are-not-visible-in-different-inWirPQD7J
TestNewPostgres-Changes-are-not-visible-in-different-ineYp0ljjI
TestNewPostgres-Successfully-connect-by-URL-and-get-verzGq4pGza
TestNewPostgres-Successfully-obtained-a-version-using-a20YgZaMf
TestNewPostgres-URL-is-different-at-different-instancesIMDkJgoP
TestNewPostgres-URL-is-different-at-different-instancesjtSsjPR5
TestUserRepository-CreateUser-Cannot-create-a-user-withmgmHFdZe
TestUserRepository-CreateUser-Successfully-created-a-UspTBGNltW
TestUserRepository-ReadUser-Get-an-error-if-the-user-doRqS1GvYh

How to use

Run make test-env-up test and then everything will happen by itself.

Disclaimer

This example is not an example of software architecture!

Description
The example suggests a solution to the problem of cleaning the database after running tests and the problem of running tests in parallel. It also shows how to organize integration testing of Go code with Postgres.
Readme BSD-3-Clause 339 KiB
Languages
Go 92.6%
Makefile 5%
Shell 2.4%