{"id":20872366,"url":"https://github.com/romnn/testcontainers","last_synced_at":"2025-05-12T13:33:41.743Z","repository":{"id":45282825,"uuid":"258585564","full_name":"romnn/testcontainers","owner":"romnn","description":"pre-configured testcontainers for your golang integration tests.","archived":false,"fork":false,"pushed_at":"2024-12-28T14:46:07.000Z","size":163,"stargazers_count":20,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T16:02:48.731Z","etag":null,"topics":["containers","docker","golang","integration-testing","kafka","minio","rabbitmq","redis","test-driven-development","testcontainers","testing-tools","zookeeper"],"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/romnn.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}},"created_at":"2020-04-24T18:00:02.000Z","updated_at":"2024-12-28T14:46:11.000Z","dependencies_parsed_at":"2024-06-18T21:22:36.553Z","dependency_job_id":"37aa6d96-5fee-41b2-b9f2-65dd9cc776ad","html_url":"https://github.com/romnn/testcontainers","commit_stats":null,"previous_names":["romnnn/testcontainers"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romnn%2Ftestcontainers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romnn%2Ftestcontainers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romnn%2Ftestcontainers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romnn%2Ftestcontainers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romnn","download_url":"https://codeload.github.com/romnn/testcontainers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253748295,"owners_count":21957902,"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":["containers","docker","golang","integration-testing","kafka","minio","rabbitmq","redis","test-driven-development","testcontainers","testing-tools","zookeeper"],"created_at":"2024-11-18T06:18:48.420Z","updated_at":"2025-05-12T13:33:41.713Z","avatar_url":"https://github.com/romnn.png","language":"Go","readme":"## testcontainers, pre-configured\n\n[![GitHub](https://img.shields.io/github/license/romnn/testcontainers)](https://github.com/romnn/testcontainers)\n[![GoDoc](https://godoc.org/github.com/romnn/testcontainers?status.svg)](https://godoc.org/github.com/romnn/testcontainers)\n[![Test Coverage](https://codecov.io/gh/romnn/testcontainers/branch/master/graph/badge.svg)](https://codecov.io/gh/romnn/testcontainers)\n\nA collection of pre-configured [testcontainers](https://github.com/testcontainers/testcontainers-go) for your golang integration tests.\n\nAvailable containers (feel free to contribute):\n\n- MongoDB (based on [mongo](https://hub.docker.com/_/mongo))\n- Kafka (based on [confluentinc/cp-kafka](https://hub.docker.com/r/confluentinc/cp-kafka) and [bitnami/zookeeper](https://hub.docker.com/r/bitnami/zookeeper))\n- RabbitMQ (based on [rabbitmq](https://hub.docker.com/_/rabbitmq))\n- Redis (based on [redis](https://hub.docker.com/_/redis/))\n- Minio (based on [minio/minio](https://hub.docker.com/r/minio/minio))\n\n### Usage\n\n##### Redis\n\n```go\n// examples/redis/redis.go\n\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/go-redis/redis\"\n\ttc \"github.com/romnn/testcontainers\"\n\ttcredis \"github.com/romnn/testcontainers/redis\"\n)\n\nfunc main() {\n\tcontainer, err := tcredis.Start(context.Background(), tcredis.Options{\n\t\tImageTag: \"7.0.5\", // you could use latest here\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to start container: %v\", err)\n\t}\n\tdefer container.Terminate(context.Background())\n\n\t// start logger\n\tlogger, err := tc.StartLogger(context.Background(), container.Container)\n\tif err != nil {\n\t\tlog.Printf(\"failed to start logger: %v\", err)\n\t} else {\n\t\tdefer logger.Stop()\n\t\tgo logger.LogToStdout()\n\t}\n\n\t// connect to redis\n\tdb := redis.NewClient(\u0026redis.Options{\n\t\tAddr:     container.ConnectionURI(),\n\t\tPassword: container.Password,\n\t\tDB:       1,\n\t})\n\n\t// set some data\n\tdb.HSet(\"my-hash-key\", \"key\", \"Hello World!\")\n\n\t// get the data back\n\tvalue, err := db.HGet(\"my-hash-key\", \"key\").Result()\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to get value: %v\", err)\n\t}\n\tif value != \"Hello World!\" {\n\t\tlog.Fatalf(`received %q instead of \"Hello World!\"`, value)\n\t}\n\n\tlog.Printf(\"received %q from redis\", value)\n}\n\n```\n\n##### MongoDB\n\n```go\n// examples/mongo/mongo.go\n\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"time\"\n\n\ttcmongo \"github.com/romnn/testcontainers/mongo\"\n\t\"go.mongodb.org/mongo-driver/bson\"\n\t\"go.mongodb.org/mongo-driver/mongo\"\n\t\"go.mongodb.org/mongo-driver/mongo/options\"\n)\n\nfunc main() {\n\tcontainer, err := tcmongo.Start(context.Background(), tcmongo.Options{\n\t\tImageTag: \"6.0.2\", // you could use latest here\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to start container: %v\", err)\n\t}\n\tdefer container.Terminate(context.Background())\n\n\t// connect to the container\n\turi := container.ConnectionURI()\n\tclient, err := mongo.NewClient(options.Client().ApplyURI(uri))\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to create client: %v\", err)\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\tdefer cancel()\n\tclient.Connect(ctx)\n\n\t// count documents in collection\n\tcollection := client.Database(\"testdatabase\").Collection(\"my-collection\")\n\topts := options.Count().SetMaxTime(2 * time.Second)\n\tcount, err := collection.CountDocuments(\n\t\tcontext.TODO(),\n\t\tbson.D{},\n\t\topts,\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to count docs in collection %q: %v\", collection.Name(), err)\n\t}\n\tlog.Printf(\"collection %q contains %d documents\", collection.Name(), count)\n}\n\n```\n\nFor more examples, see `examples/`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromnn%2Ftestcontainers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromnn%2Ftestcontainers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromnn%2Ftestcontainers/lists"}