{"id":23843881,"url":"https://github.com/oppodelldog/dockertest","last_synced_at":"2026-06-17T23:31:13.941Z","repository":{"id":57492345,"uuid":"207091396","full_name":"Oppodelldog/dockertest","owner":"Oppodelldog","description":"run functional tests in containers - orchestrated in go","archived":false,"fork":false,"pushed_at":"2024-04-19T12:18:45.000Z","size":1742,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T06:13:01.774Z","etag":null,"topics":["docker","dockertest","functional-testing","orchestration","system-testing","test"],"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/Oppodelldog.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}},"created_at":"2019-09-08T09:43:30.000Z","updated_at":"2021-11-15T23:00:49.000Z","dependencies_parsed_at":"2023-10-15T16:22:56.776Z","dependency_job_id":"a00f433f-0a3d-4ada-82cd-fcc3fa898232","html_url":"https://github.com/Oppodelldog/dockertest","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/Oppodelldog/dockertest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oppodelldog%2Fdockertest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oppodelldog%2Fdockertest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oppodelldog%2Fdockertest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oppodelldog%2Fdockertest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oppodelldog","download_url":"https://codeload.github.com/Oppodelldog/dockertest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oppodelldog%2Fdockertest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273094224,"owners_count":25044440,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["docker","dockertest","functional-testing","orchestration","system-testing","test"],"created_at":"2025-01-02T19:51:28.817Z","updated_at":"2026-06-17T23:31:13.916Z","avatar_url":"https://github.com/Oppodelldog.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dockertest\n[![GoDoc](https://godoc.org/github.com/Oppodelldog/dockertest?status.svg)](https://godoc.org/github.com/Oppodelldog/dockertest)\n[![Go Report Card](https://goreportcard.com/badge/github.com/Oppodelldog/dockertest)](https://goreportcard.com/report/github.com/Oppodelldog/dockertest)\n[![Build Status](https://travis-ci.org/Oppodelldog/dockertest.svg?branch=master)](https://travis-ci.org/Oppodelldog/dockertest)\n\n![DOCKERTEST](whaleneedshelp.png)\n\nThis project is an experimental library that wraps the docker client to ease testing services in docker containers.\n\nI split it out from my docker-dns project where I found the need for functional testing a dns-container behaving well after build.\n\nThe rough concept is as follows:\n* create a ```ContainerBuilder``` (which takes basic parameters)\n* if necessay modify the docker-client data structures which are exposed by the builder\n* use the builder to create a ```Container```\n* use ```Container``` to start\n\nAdditional to the creation and starting of containers there are convenicence methods like\n```WaitForContainerToExit``` which waits for the container executing tests,\n\nFor debugging those tests it is useful to use method ```DumpContainerLogs``` to take a look inside the components under test.\n\nFinally ```Cleanup()``` the whole setup, jenkins will love you for that. \n\n## Example\nHere's one example simulating how to test an api with two containers.\n \nMore information here: [examples/api/README.md](examples/api/README.md)\n \n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\t\"time\"\n\n\t\"github.com/Oppodelldog/dockertest\"\n)\n\nconst waitingTimeout = time.Minute\n\n// functional tests for name api.\n// nolint:funlen\nfunc main() {\n\t// the local test dir will help mounting the project into the containers\n\tprojectDir, err := os.Getwd()\n\tpanicOnErr(err)\n\n\t// start a new test\n\ttest, err := dockertest.NewSession()\n\tpanicOnErr(err)\n\n\tgo cancelSessionOnSigTerm(test)\n\n\t// cleanup resources from a previous test\n\ttest.CleanupRemains()\n\n\t// initialize testResult which is passed into deferred cleanup method\n\tvar testResult = TestResult{ExitCode: -1}\n\tdefer cleanup(test, \u0026testResult)\n\n\t// let put test log output into a separate directory\n\ttest.SetLogDir(\"examples/api/test-logs\")\n\n\t// since it's a micro-service api test, we need networking facility\n\tnet, err := test.CreateBasicNetwork(\"test-network\").Create()\n\tpanicOnErr(err)\n\n\tbasicConfiguration := test.NewContainerBuilder().\n\t\tImage(\"golang:1.19.0\").\n\t\tConnect(net).\n\t\tWorkingDir(\"/app/examples/api\").\n\t\tMount(projectDir, \"/app\")\n\n\t// create the API container, the system under test\n\tapi, err := basicConfiguration.NewContainerBuilder().\n\t\tName(\"api\").\n\t\tCmd(\"go run nameapi/main.go\").\n\t\tEnv(\"API_BASE_URL\", \"http://localhost:8080\").\n\t\tHealthShellCmd(\"go run healthcheck/main.go\").\n\t\tBuild()\n\tpanicOnErr(err)\n\n\t// create the testing container\n\ttests, err := basicConfiguration.NewContainerBuilder().\n\t\tName(\"tests\").\n\t\tCmd(\"go test -v tests/api_test.go\").\n\t\tLink(api, \"api\", net).\n\t\tEnv(\"API_BASE_URL\", \"http://api:8080\").\n\t\tBuild()\n\tpanicOnErr(err)\n\n\t// start api containers\n\terr = api.Start()\n\tpanicOnErr(err)\n\n\t// wait until API is available\n\terr = \u003c-test.NotifyContainerHealthy(api, waitingTimeout)\n\tpanicOnErr(err)\n\n\t// now start the tests\n\terr = tests.Start()\n\tpanicOnErr(err)\n\n\t// wait for tests to finish\n\t\u003c-test.NotifyContainerExit(tests, waitingTimeout)\n\n\t// grab the exit code from the exited container\n\ttestResult.ExitCode, err = tests.ExitCode()\n\tpanicOnErr(err)\n\n\t// dump the test output to the log directory\n\ttest.DumpContainerLogs(tests)\n}\n\nfunc cancelSessionOnSigTerm(session *dockertest.Session) {\n\tsigCh := make(chan os.Signal, 1)\n\tsignal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)\n\t\u003c-sigCh\n\tsession.Cancel()\n}\n\n// it is always a good practise to clean up.\nfunc cleanup(test *dockertest.Session, testResult *TestResult) {\n\tfmt.Println(\"CLEANUP-START\")\n\ttest.Cleanup()\n\tfmt.Println(\"CLEANUP-DONE\")\n\n\tif r := recover(); r != nil {\n\t\tfmt.Printf(\"ERROR: %v\\n\", r)\n\t}\n\n\tos.Exit(testResult.ExitCode)\n}\n\n// TestResult helps to share the exit code through a defer to the cleanup function.\ntype TestResult struct {\n\tExitCode int\n}\n\nfunc panicOnErr(err error) {\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tpanic(err)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foppodelldog%2Fdockertest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foppodelldog%2Fdockertest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foppodelldog%2Fdockertest/lists"}