{"id":36469516,"url":"https://github.com/xorcare/testing-go-code-with-postgres","last_synced_at":"2026-01-12T00:33:00.109Z","repository":{"id":178766074,"uuid":"648954545","full_name":"xorcare/testing-go-code-with-postgres","owner":"xorcare","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.","archived":false,"fork":false,"pushed_at":"2025-12-02T02:20:20.000Z","size":93,"stargazers_count":26,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-04T18:28:18.249Z","etag":null,"topics":["go","golang","integration-tests","postgres","postgresql","testing","tests"],"latest_commit_sha":null,"homepage":"https://xorcare.ru/s/7cfd5","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xorcare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-06-03T10:13:43.000Z","updated_at":"2025-12-02T02:20:23.000Z","dependencies_parsed_at":"2024-03-14T17:49:38.420Z","dependency_job_id":"2ad14ffb-7970-4dc3-bd95-cd13667b6467","html_url":"https://github.com/xorcare/testing-go-code-with-postgres","commit_stats":null,"previous_names":["xorcare/testing-go-code-with-postgres"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xorcare/testing-go-code-with-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xorcare%2Ftesting-go-code-with-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xorcare%2Ftesting-go-code-with-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xorcare%2Ftesting-go-code-with-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xorcare%2Ftesting-go-code-with-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xorcare","download_url":"https://codeload.github.com/xorcare/testing-go-code-with-postgres/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xorcare%2Ftesting-go-code-with-postgres/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28329798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:13:06.322Z","status":"ssl_error","status_checked_at":"2026-01-12T00:04:50.725Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","integration-tests","postgres","postgresql","testing","tests"],"created_at":"2026-01-12T00:32:56.992Z","updated_at":"2026-01-12T00:33:00.104Z","avatar_url":"https://github.com/xorcare.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example of testing Go code with Postgres\n\n[![Go workflow status badge](https://github.com/xorcare/testing-go-code-with-postgres/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/xorcare/testing-go-code-with-postgres/actions/workflows/go.yml)\n[![codecov](https://codecov.io/github/xorcare/testing-go-code-with-postgres/branch/main/graph/badge.svg?token=AmPmVHf2ej)](https://codecov.io/github/xorcare/testing-go-code-with-postgres/tree/main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/xorcare/testing-go-code-with-postgres)](https://goreportcard.com/report/github.com/xorcare/testing-go-code-with-postgres)\n\nThe example suggests a solution to the problem of cleaning the database after\nrunning tests and the problem of running tests in parallel. It also shows how\nto organize integration testing of Go code with Postgres.\n\n## Quick start\n\nFor quickly try integration tests locally, use following commands.\n\n```shell\ngit clone https://github.com/xorcare/testing-go-code-with-postgres\ncd testing-go-code-with-postgres\nmake test-env-up test\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of output\u003c/summary\u003e\n\n```text\n❯ git clone https://github.com/xorcare/testing-go-code-with-postgres\ncd testing-go-code-with-postgres\nmake test-env-up test\nCloning into 'testing-go-code-with-postgres'...\nremote: Enumerating objects: 103, done.\nremote: Counting objects: 100% (45/45), done.\nremote: Compressing objects: 100% (24/24), done.\nremote: Total 103 (delta 26), reused 29 (delta 20), pack-reused 58\nReceiving objects: 100% (103/103), 27.58 KiB | 3.94 MiB/s, done.\nResolving deltas: 100% (40/40), done.\n[+] Running 15/15\n ✔ migrate 5 layers [⣿⣿⣿⣿⣿]      0B/0B      Pulled                                             5.0s \n   ✔ 08409d417260 Pull complete                                                                1.5s \n   ✔ 2f9061c5186e Pull complete                                                                0.8s \n   ✔ de4eb1257b2b Pull complete                                                                2.2s \n   ✔ 750ec3989a15 Pull complete                                                                1.6s \n   ✔ 586322a68347 Pull complete                                                                2.2s \n ✔ postgres 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                        15.2s \n   ✔ 9fda8d8052c6 Pull complete                                                                2.5s \n   ✔ b0d9bb38da5c Pull complete                                                                2.8s \n   ✔ a99f2e61e525 Pull complete                                                                2.8s \n   ✔ eb307cc1ffd3 Pull complete                                                               11.1s \n   ✔ 99aedaa309df Pull complete                                                                4.0s \n   ✔ 1d4087443ab6 Pull complete                                                                3.5s \n   ✔ 278b6fc01aef Pull complete                                                                4.2s \n   ✔ 024b1a6a5c4d Pull complete                                                                4.9s \n[+] Building 0.0s (0/0)                                                              docker:default\n[+] Running 3/2\n ✔ Network testing-go-code-with-postgres_default       Created                                 0.0s \n ✔ Container testing-go-code-with-postgres-postgres-1  Created                                 0.2s \n ✔ Container testing-go-code-with-postgres-migrate-1   Created                                 0.0s \nAttaching to testing-go-code-with-postgres-migrate-1\ntesting-go-code-with-postgres-migrate-1  | 1/u create_users_table (4.481416ms)\ntesting-go-code-with-postgres-migrate-1 exited with code 0\nAborting on container exit...\n[+] Stopping 1/0\n ✔ Container testing-go-code-with-postgres-migrate-1  Stopped                                  0.0s \nok  \tgithub.com/xorcare/testing-go-code-with-postgres\t1.500s\tcoverage: 100.0% of statements\nok  \tgithub.com/xorcare/testing-go-code-with-postgres/testingpg\t1.764s\tcoverage: 100.0% of statements\ntotal:\t(statements)\t100.0%\n```\n\n\u003c/details\u003e\n\n## Thank you for your support\n\nIf you found this project useful, please support it by giving it a star\non [GitHub](https://github.com/xorcare/testing-go-code-with-postgres).\nThis will help other users discover the project and will motivate me to continue developing it!\nThank you for your support!\n\n## What's interesting here?\n\n- Example\n  of [docker-compose.yml](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/docker-compose.yml)\n  with multiple databases and automated migrations.\n- Example of test database connection management\n  in [testingpg](https://github.com/xorcare/testing-go-code-with-postgres/tree/main/testingpg)\n  package.\n- [Example of integration testing with isolated database for each testcase](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/user_repository_with_isolated_database_test.go).\n- [Example of integration testing with transaction cleanup for each testcase](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/user_repository_with_transactional_cleanup_test.go).\n- [Example of integration testing with isolated schema for each testcase](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/user_repository_with_isolated_schema_test.go).\n- And example\n  of [GitHub Actions](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/.github/workflows/go.yml)\n  and [Gitlab CI](https://github.com/xorcare/testing-go-code-with-postgres/blob/main/.gitlab-ci.yml).\n\nGenerating human-readable database names from `t.Name()` to simplifying problem investigation.\nThe last 8 characters are a short unique identifier needed to prevent name collision, its necessary\nbecause the maximum length of the name is 63 bytes, and the name must be unique.\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of test names\u003c/summary\u003e\n\n```text\nTestNewPostgres-Changes-are-not-visible-in-different-inWirPQD7J\nTestNewPostgres-Changes-are-not-visible-in-different-ineYp0ljjI\nTestNewPostgres-Successfully-connect-by-URL-and-get-verzGq4pGza\nTestNewPostgres-Successfully-obtained-a-version-using-a20YgZaMf\nTestNewPostgres-URL-is-different-at-different-instancesIMDkJgoP\nTestNewPostgres-URL-is-different-at-different-instancesjtSsjPR5\nTestUserRepository-CreateUser-Cannot-create-a-user-withmgmHFdZe\nTestUserRepository-CreateUser-Successfully-created-a-UspTBGNltW\nTestUserRepository-ReadUser-Get-an-error-if-the-user-doRqS1GvYh\n```\n\n\u003c/details\u003e\n\n## Known issues\n\nWhen using **colima** on macos you may have problems if you clone this project to a temporary\ndirectory like this:\n\n```text\n/var/folders/3p/glp5vp4916n03wmjh_b0gf6m0000gn/T/tmp.lbM4pbW2/testing-go-code-with-postgres\n```\n\nThis problem is caused by incorrect mounting of files, and looks like this:\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of output\u003c/summary\u003e\n\n```text\n/var/folders/3p/glp5vp4916n03wmjh_b0gf6m0000gn/T/tmp.lbM4pbW2/testing-go-code-with-postgres\n❯ docker-compose up\n...\ntesting-go-code-with-postgres-postgres-1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/docker-multiple-databases.sh\ntesting-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\ntesting-go-code-with-postgres-postgres-1 exited with code 126\ndependency failed to start: container testing-go-code-with-postgres-postgres-1 exited (126)\n```\n\n\u003c/details\u003e\n\n## Disclaimer\n\n**This example is not an example of software architecture!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxorcare%2Ftesting-go-code-with-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxorcare%2Ftesting-go-code-with-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxorcare%2Ftesting-go-code-with-postgres/lists"}