{"id":13397025,"url":"https://github.com/orlangure/gnomock","last_synced_at":"2025-05-14T00:03:24.013Z","repository":{"id":37034416,"uuid":"237450763","full_name":"orlangure/gnomock","owner":"orlangure","description":"Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻","archived":false,"fork":false,"pushed_at":"2025-05-12T11:44:20.000Z","size":1642,"stargazers_count":1436,"open_issues_count":26,"forks_count":70,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-12T12:42:05.101Z","etag":null,"topics":["cockroachdb","docker","elasticsearch","end-to-end-testing","go","golang","hacktoberfest","integration-testing","kafka","kubernetes","mariadb","memcached","mongo","mysql","postgres","rabbitmq","redis","splunk","sql-server","testing"],"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/orlangure.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"orlangure"}},"created_at":"2020-01-31T14:50:52.000Z","updated_at":"2025-05-12T11:44:23.000Z","dependencies_parsed_at":"2024-05-22T18:50:00.153Z","dependency_job_id":"d96fdcb3-4499-4e2f-95a2-de4582efdf50","html_url":"https://github.com/orlangure/gnomock","commit_stats":{"total_commits":573,"total_committers":22,"mean_commits":"26.045454545454547","dds":0.3612565445026178,"last_synced_commit":"4ebce3a956f789c98d670044cea5690d2b8d0639"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlangure%2Fgnomock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlangure%2Fgnomock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlangure%2Fgnomock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlangure%2Fgnomock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orlangure","download_url":"https://codeload.github.com/orlangure/gnomock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253744567,"owners_count":21957309,"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":["cockroachdb","docker","elasticsearch","end-to-end-testing","go","golang","hacktoberfest","integration-testing","kafka","kubernetes","mariadb","memcached","mongo","mysql","postgres","rabbitmq","redis","splunk","sql-server","testing"],"created_at":"2024-07-30T18:01:09.634Z","updated_at":"2025-05-14T00:03:23.895Z","avatar_url":"https://github.com/orlangure.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/orlangure/gnomock/raw/master/gnomock.png\"\u003e\n\u003c/div\u003e\n\n# \u003cdiv align=\"center\"\u003eGnomock – tests without mocks\u003c/div\u003e\n\n🏗️ Spin up entire dependency stack\n\n🎁 Setup initial dependency state – easily!\n\n🏭 Test against actual, close to production software\n\n⏳ Spend no time writing mocks\n\n🕹️ Test actual program behavior and side effects\n\n## \u003cdiv align=\"center\"\u003e[![PkgGoDev](https://pkg.go.dev/badge/github.com/orlangure/gnomock)](https://pkg.go.dev/github.com/orlangure/gnomock) ![Test](https://github.com/orlangure/gnomock/workflows/Test/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/orlangure/gnomock)](https://goreportcard.com/report/github.com/orlangure/gnomock) [![codecov](https://codecov.io/gh/orlangure/gnomock/branch/master/graph/badge.svg?token=F0XYPSEIMK)](https://codecov.io/gh/orlangure/gnomock)\u003c/div\u003e\n\nGnomock is an integration and end-to-end testing toolkit. It uses Docker to create **temporary containers** for application dependencies, **setup** their **initial state** and **clean them up** in the end. Gnomock allows to test the code with **no mocks** wherever possible.\n\nThe power of Gnomock is in a variety of [Presets](#official-presets), each implementing a specific database, service or other tools. Each preset provides ways of setting up its initial state as easily as possible: SQL schema creation, test data upload into S3, sending test events to Splunk, etc.\n\nThe name \"Gnomock\" stands for \"no mock\", with a \"G\" for \"Go\" 😼. It also sounds like \"gnome\", that's why the friendly garden gnome artwork (by [Michael Zolotov](https://www.mzolotov.com/))\n\n## Demo\n\nSee for yourself how easy and fast it is to write tests that use actual services running in ephemeral Docker containers:\n\n[![asciicast](https://asciinema.org/a/jSJJGk0n3q1g4Fc4bvZYYyifN.svg)](https://asciinema.org/a/jSJJGk0n3q1g4Fc4bvZYYyifN)\n\n## Table of contents\n\n- [Getting started](#getting-started)\n  - [Using Gnomock in Go applications](#using-gnomock-in-go-applications)\n  - [Using Gnomock in other languages](#using-gnomock-in-other-languages)\n- [Official presets](#official-presets)\n- [Similar projects](#similar-projects)\n- [Troubleshooting](#troubleshooting)\n- [Giving back](#giving-back) 💰\n\n## Getting started\n\nGnomock can be used in two different ways:\n\n- Imported directly as a package in any **Go** project\n- Accessed over HTTP running as a daemon in **any other language**\n\nBoth ways **require** an active Docker daemon running **locally** in the same environment.\n\nExternal `DOCKER_HOST` support is experimental. It cannot be reliably tested at this moment, but it might work.\n\n### Using Gnomock in Go applications\n\nSee the following example to get started:\n\n```\ngo get github.com/orlangure/gnomock\n```\n\nSetting up a **Postgres** container with schema setup example:\n\n```go\npackage db_test\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\t\"testing\"\n\n\t_ \"github.com/lib/pq\" // postgres driver\n\t\"github.com/orlangure/gnomock\"\n\t\"github.com/orlangure/gnomock/preset/postgres\"\n)\n\nfunc TestDB(t *testing.T) {\n\tp := postgres.Preset(\n\t\tpostgres.WithUser(\"gnomock\", \"gnomick\"),\n\t\tpostgres.WithDatabase(\"mydb\"),\n\t\tpostgres.WithQueriesFile(\"/var/project/db/schema.sql\"),\n\t)\n\tcontainer, _ := gnomock.Start(p)\n\tt.Cleanup(func() { _ = gnomock.Stop(container) })\n\n\tconnStr := fmt.Sprintf(\n\t\t\"host=%s port=%d user=%s password=%s  dbname=%s sslmode=disable\",\n\t\tcontainer.Host, container.DefaultPort(),\n\t\t\"gnomock\", \"gnomick\", \"mydb\",\n\t)\n\tdb, _ := sql.Open(\"postgres\", connStr)\n\t// db has the required schema and data, and is ready to use\n}\n```\n\nSee package [reference](https://pkg.go.dev/github.com/orlangure/gnomock?tab=doc). For Preset documentation, refer to [Presets](#official-presets) section.\n\n### Using Gnomock in other languages\n\nIf you use Go, please refer to [Using Gnomock in Go applications](#using-gnomock-in-go-applications) section. Otherwise, refer to [documentation](docs/server.md).\n\n## Official presets\n\nThe power of Gnomock is in the Presets. Existing Presets with their supported\u003csup\u003e\\*\u003c/sup\u003e versions are listed below.\n\n\u003csmall\u003e*\\* **Supported** versions are tested as part of CI pipeline. Other versions might work as well.*\u003c/small\u003e\n\n| Preset | Go package | Go API | Supported versions                        | arm64 |\n|--------|------------|--------|-------------------------------------------|-------|\n[Localstack](https://github.com/localstack/localstack) (AWS) | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/localstack) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/localstack?tab=doc) | `0.12.2`, `0.13.1`, `0.14.0`, `2.3.0`, `3.1.0`              | ✅\nSplunk | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/splunk) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/splunk?tab=doc) | `8.0.2`                                   | ❌\nRedis | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/redis) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/redis?tab=doc) | `5.0.10`, `6.0.9`, `7.2.4`                         | ✅\nMemcached | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/memcached) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/memcached?tab=doc) | `1.6.9`, `1.6.23`                                   | ✅\nMySQL | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/mysql) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/mysql?tab=doc) | `5.7.32`, `8.0.22`                        | ✅\nMariaDB | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/mariadb) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/mariadb?tab=doc) | `10.5.8`, `11.2.2`                                  | ✅\nPostgreSQL | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/postgres) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/postgres?tab=doc) | `10.15`, `11.10`, `12.5`, `13.1`, `14.11`, `15.6`, `16.2`          | ✅\nMicrosoft SQL Server | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/mssql) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/mssql?tab=doc) | `2017-latest`, `2019-latest`              | ❌\nMongoDB | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/mongo) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/mongo?tab=doc) | `3.6.21`, `4.4`, `5.0`                           | ✅\nRabbitMQ | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/rabbitmq) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/rabbitmq?tab=doc) | `3.8.9-alpine`, `3.8.9-management-alpine`, `3.13-alpine` | ✅\nKafka | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/kafka) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/kafka?tab=doc) | `3.3.1-L0`,  `3.6.1-L0`                                       | ✅\nElasticsearch | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/elastic) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/elastic?tab=doc) | `8.13.0`, `7.17.21`                         | ✅\nKubernetes | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/k3s) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/k3s?tab=doc) | `v1.26.3-k3s1`                            | ✅\nCockroachDB | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/cockroachdb) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/cockroachdb?tab=doc) | `v20.1.10`, `v21.2.17`, `v22.2.19`, `v23.1.20`                    | ✅\nInfluxDB | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/influxdb) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/influxdb?tab=doc) | `2.7.6-alpine`                            | ✅\nCassandra | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/cassandra) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/cassandra?tab=doc) | `4.0`, `3`                                | ✅\nVault | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/vault) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/vault?tab=doc) | `1.10`, `1.11`, `1.12`, `1.13`     | ✅\nAzurite | [Go package](https://github.com/orlangure/gnomock/tree/master/preset/azurite) | [Reference](https://pkg.go.dev/github.com/orlangure/gnomock/preset/azurite?tab=doc) | `3.30.0`                                  | ✅\n\u003c!-- new presets go here --\u003e\n\nIt is possible to use Gnomock [directly from Go](https://pkg.go.dev/github.com/orlangure/gnomock#StartCustom) code without any presets. HTTP API only allows to setup containers using presets that exist in this repository.\n\n## Similar projects\n\nGnomock is not the only project that aims to simplify integration and end-to-end testing by using ephemeral docker containers:\n\n- `testcontainers/testcontainers-go`\n- `ory/dockertest`\n\nThese projects are amazing, and they give plenty of flexibility and power to their users. There are many things that are possible with them, but are impossible with Gnomock. Still, below is a short list of things that sometimes give Gnomock an advantage:\n\n- **Gnomock tries to provide a batteries-included solution**. Gnomock has a growing number of Presets, each one implementing an integration with a popular external service. For every Preset, there already is a number of \"invisible\" utilities that transparently relieve you from implementing them yourself:\n  - __Built-in health check function__ that you don't even need to know it exists. It makes sure you only get control over a container when it is ready to use.\n  - __Wrappers for some of the configuration__ exposed by the container, such as default username/password. You can easily provide your own credentials to connect to the container.\n  - __Seed data ingestion__ for your convenience. Sometimes you just need to make sure your queries work given some data. Gnomock puts your data in there with a single line of code. Sometimes you only test a program that consumes messages from Kafka, and Gnomock produces the messages for you with another line of code.\n- **Simple API** that does not expose anything that happens \"under the hood\" most of the time. Yet Gnomock allows some additional configuration and custom Preset implementation whenever necessary.\n- Gnomock's vision includes **being useful not only in Go** projects, but in any projects via HTTP. It already supports almost all its features over HTTP layer and has a clear OpenAPI spec.\n- Gnomock has a friendly **garden gnome mascot**😻\n\n## Troubleshooting\n\n### Tests with Gnomock take too long and time-out eventually\n\nIt happens a lot locally if your internet isn't fast enough to pull docker images used in tests. In CI, such as in Github Actions, the images are downloaded very quickly. To work around this issue locally, pull the image manually before running the tests. You only need to do it once, the images stay in local cache until deleted. For example, to pull Postgres 11 image, run:\n\n```\ndocker pull postgres:11\n```\n\n### Tests time-out even when the image exists locally\n\nIt can happen if the containers can't become ready to use before they time out. By default, Gnomock uses fairly high timeouts for new containers (for starting and for setting them up). If you choose to change default timeout using `WithTimeout` (`timeout` in HTTP), it is possible that the values you choose are too short.\n\n### Tests pass when run one-by-one, and fail when run in parallel\n\nIt happens when you try to start up **a lot** of containers at the same time. The system, especially in CI environments such as Github Actions, cannot handle the load, and containers fail to become healthy before they time-out. That's the reason Gnomock has a few separate build jobs, each running only a small subset of tests, one package at a time.\n\n### Containers fail to setup with a \"File not found\" error\n\nIf you run `gnomock` as a server, you need to make sure the files you use in your setup are available inside `gnomock` container. Use `-v $(pwd):$(pwd)` argument to `docker run` to mount the current working directory under the same path inside the `gnomock` container. If you prefer to keep a permanent `gnomock` container running, you can mount your entire `$HOME` directory (or any other directory where you keep the code).\n\n## Giving back\n\nThis is a free and open source project that hopefully helps its users, at least a little. Even though I don't need donations to support it, I understand that there are people that wish to give back anyway. If you are one of them, I encourage you to [plant some trees with Tree Nation](https://tree-nation.com/plant/offer) 🌲 🌳 🌴\n\nIf you want me to know about your contribution, make sure to use `orlangure+gnomock@gmail.com` as the recipient email.\n\nThank you!\n","funding_links":["https://github.com/sponsors/orlangure"],"categories":["Go","开源类库","Testing","Repositories","Open source library","测试","语言资源库","年度文章盘点","Template Engines","Testing Frameworks"],"sub_categories":["测试","HTTP Clients","Test","HTTP客户端","go","Testing Frameworks","2021年度文章盘点"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlangure%2Fgnomock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forlangure%2Fgnomock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlangure%2Fgnomock/lists"}