{"id":13413867,"url":"https://github.com/fergusstrange/embedded-postgres","last_synced_at":"2025-04-14T00:51:41.557Z","repository":{"id":36766418,"uuid":"222173889","full_name":"fergusstrange/embedded-postgres","owner":"fergusstrange","description":"Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test","archived":false,"fork":false,"pushed_at":"2024-08-26T10:25:32.000Z","size":402,"stargazers_count":810,"open_issues_count":4,"forks_count":83,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-27T12:57:21.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fergusstrange.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2019-11-16T23:49:40.000Z","updated_at":"2024-08-27T07:34:32.000Z","dependencies_parsed_at":"2024-02-28T10:25:58.826Z","dependency_job_id":"d9269218-b3eb-4ef1-a638-f83cae0c2c17","html_url":"https://github.com/fergusstrange/embedded-postgres","commit_stats":{"total_commits":127,"total_committers":28,"mean_commits":4.535714285714286,"dds":"0.49606299212598426","last_synced_commit":"efb8f5554a17428524fc8e5ba965513fe0356329"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fergusstrange%2Fembedded-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fergusstrange%2Fembedded-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fergusstrange%2Fembedded-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fergusstrange%2Fembedded-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fergusstrange","download_url":"https://codeload.github.com/fergusstrange/embedded-postgres/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804773,"owners_count":21164131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-07-30T20:01:51.540Z","updated_at":"2025-04-14T00:51:41.537Z","avatar_url":"https://github.com/fergusstrange.png","language":"Go","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/fergusstrange/embedded-postgres/master/gopher.png\" width=\"150\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://godoc.org/github.com/fergusstrange/embedded-postgres\"\u003e\u003cimg src=\"https://godoc.org/github.com/fergusstrange/embedded-postgres?status.svg\" alt=\"Godoc\" /\u003e\u003c/a\u003e\n\u003ca href='https://coveralls.io/github/fergusstrange/embedded-postgres?branch=master'\u003e\u003cimg src='https://coveralls.io/repos/github/fergusstrange/embedded-postgres/badge.svg?branch=master' alt='Coverage Status' /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/fergusstrange/embedded-postgres/actions\"\u003e\u003cimg src=\"https://github.com/fergusstrange/embedded-postgres/workflows/Embedded%20Postgres/badge.svg\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://app.circleci.com/pipelines/github/fergusstrange/embedded-postgres\"\u003e\u003cimg src=\"https://circleci.com/gh/fergusstrange/embedded-postgres.svg?style=shield\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/fergusstrange/embedded-postgres\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/fergusstrange/embedded-postgres\" alt=\"Go Report Card\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# embedded-postgres\n\nRun a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test.\n\nWhen testing this provides a higher level of confidence than using any in memory alternative. It also requires no other\nexternal dependencies outside of the Go build ecosystem.\n\nHeavily inspired by Java projects [zonkyio/embedded-postgres](https://github.com/zonkyio/embedded-postgres)\nand [opentable/otj-pg-embedded](https://github.com/opentable/otj-pg-embedded) and reliant on the great work being done\nby [zonkyio/embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries) in order to fetch\nprecompiled binaries\nfrom [Maven](https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom).\n\n## Installation\n\nembedded-postgres uses Go modules and as such can be referenced by release version for use as a library. Use the\nfollowing to add the latest release to your project.\n\n```bash\ngo get -u github.com/fergusstrange/embedded-postgres\n``` \n\n## How to use\n\nThis library aims to require as little configuration as possible, favouring overridable defaults\n\n| Configuration       | Default Value                                   |\n|---------------------|-------------------------------------------------|\n| Username            | postgres                                        |\n| Password            | postgres                                        |\n| Database            | postgres                                        |\n| Version             | 15.3.0                                          |\n| Encoding            | UTF8                                            |\n| Locale              | C                                               |\n| Version             | 15.3.0                                          |\n| CachePath           | $USER_HOME/.embedded-postgres-go/               |\n| RuntimePath         | $USER_HOME/.embedded-postgres-go/extracted      |\n| DataPath            | $USER_HOME/.embedded-postgres-go/extracted/data |\n| BinariesPath        | $USER_HOME/.embedded-postgres-go/extracted      |\n| BinaryRepositoryURL | https://repo1.maven.org/maven2                  |\n| Port                | 5432                                            |\n| StartTimeout        | 15 Seconds                                      |\n| StartParameters     | map[string]string{\"max_connections\": \"101\"}     |\n\nThe *RuntimePath* directory is erased and recreated at each `Start()` and therefore not suitable for persistent data.\n\nIf a persistent data location is required, set *DataPath* to a directory outside *RuntimePath*.\n\nIf the *RuntimePath* directory is empty or already initialized but with an incompatible postgres version, it will be\nremoved and Postgres reinitialized.\n\nPostgres binaries will be downloaded and placed in *BinaryPath* if `BinaryPath/bin` doesn't exist.\n*BinaryRepositoryURL* parameter allow overriding maven repository url for Postgres binaries.\nIf the directory does exist, whatever binary version is placed there will be used (no version check\nis done).  \nIf your test need to run multiple different versions of Postgres for different tests, make sure\n*BinaryPath* is a subdirectory of *RuntimePath*.\n\nA single Postgres instance can be created, started and stopped as follows\n\n```go\npostgres := embeddedpostgres.NewDatabase()\nerr := postgres.Start()\n\n// Do test logic\n\nerr := postgres.Stop()\n```\n\nor created with custom configuration\n\n```go\nlogger := \u0026bytes.Buffer{}\npostgres := NewDatabase(DefaultConfig().\nUsername(\"beer\").\nPassword(\"wine\").\nDatabase(\"gin\").\nVersion(V12).\nRuntimePath(\"/tmp\").\nBinaryRepositoryURL(\"https://repo.local/central.proxy\").\nPort(9876).\nStartTimeout(45 * time.Second).\nStartParameters(map[string]string{\"max_connections\": \"200\"}).\nLogger(logger))\nerr := postgres.Start()\n\n// Do test logic\n\nerr := postgres.Stop()\n```\n\nIt should be noted that if `postgres.Stop()` is not called then the child Postgres process will not be released and the\ncaller will block.\n\n## Examples\n\nThere are a number of realistic representations of how to use this library\nin [examples](https://github.com/fergusstrange/embedded-postgres/tree/master/examples).\n\n## Credits\n\n- [Gopherize Me](https://gopherize.me) Thanks for the awesome logo template.\n- [zonkyio/embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries) Without which the\n  precompiled Postgres binaries would not exist for this to work.\n\n## Contributing\n\nView the [contributing guide](CONTRIBUTING.md).\n\n","funding_links":[],"categories":["Template Engines","Testing","Go","测试","测试相关`测试库和测试数据集生成库`","测试相关","Testing Frameworks"],"sub_categories":["Testing Frameworks","HTTP客户端","HTTP Clients","查询语"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffergusstrange%2Fembedded-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffergusstrange%2Fembedded-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffergusstrange%2Fembedded-postgres/lists"}