{"id":18875810,"url":"https://github.com/wiremock/go-wiremock","last_synced_at":"2025-04-09T08:11:32.971Z","repository":{"id":43657337,"uuid":"305109049","full_name":"wiremock/go-wiremock","owner":"wiremock","description":"Golang WireMock admin API client ","archived":false,"fork":false,"pushed_at":"2024-10-22T20:55:55.000Z","size":302,"stargazers_count":51,"open_issues_count":3,"forks_count":19,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T06:07:34.961Z","etag":null,"topics":["golang","hacktoberfest","wiremock","wiremock-admin"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/wiremock/go-wiremock?utm_source=godoc","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/wiremock.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-10-18T13:33:30.000Z","updated_at":"2025-03-10T10:32:29.000Z","dependencies_parsed_at":"2024-11-16T14:15:23.911Z","dependency_job_id":null,"html_url":"https://github.com/wiremock/go-wiremock","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgo-wiremock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgo-wiremock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgo-wiremock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgo-wiremock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiremock","download_url":"https://codeload.github.com/wiremock/go-wiremock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999864,"owners_count":21031046,"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":["golang","hacktoberfest","wiremock","wiremock-admin"],"created_at":"2024-11-08T06:09:15.078Z","updated_at":"2025-04-09T08:11:32.950Z","avatar_url":"https://github.com/wiremock.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-wiremock\n\n[![GoDoc](https://godoc.org/github.com/wiremock/go-wiremock?status.svg)](http://godoc.org/github.com/wiremock/go-wiremock)\n[![Actions Status](https://github.com/wiremock/go-wiremock/workflows/build/badge.svg)](https://github.com/wiremock/go-wiremock/actions?query=workflow%3Abuild)\n[![Slack](https://img.shields.io/badge/slack.wiremock.org-%23wiremock—go-brightgreen?style=flat\u0026logo=slack)](https://slack.wiremock.org/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wiremock/go-wiremock)](https://goreportcard.com/report/github.com/wiremock/go-wiremock)\n\n\u003ca href=\"https://go.wiremock.org\" target=\"_blank\"\u003e\n    \u003cimg width=\"128px\" align=\"right\" src=\"docs/images/logo/logo.png\" alt=\"Go WireMock Logo\"/\u003e\n\u003c/a\u003e\n\nThe Golang client library to stub API resources in [WireMock](https://wiremock.org) using its\n[REST API](https://wiremock.org/docs/api/).\nThe project connects to the instance and allows\nsetting up stubs and response templating,\nor using administrative API to extract observability data.\n\nLearn more: [Golang \u0026 WireMock Solutions page]( https://wiremock.org/docs/solutions/golang/)\n\n## Documentation\n\n[![GoDoc](https://godoc.org/github.com/wiremock/go-wiremock?status.svg)](http://godoc.org/github.com/wiremock/go-wiremock)\n\n## Compatibility\n\nThe library was tested with the following distributions\nof WireMock:\n\n- WireMock 2.x - standalone deployments, including but not limited to official Docker images, Helm charts and the Java executable\n- WireMock 3.x Beta - partial support, some features are\n  yet to be implemented. Contributions are welcome!\n- [WireMock Cloud](https://www.wiremock.io/product) -\n  proprietary SaaS edition by WireMock Inc.\n\nNote that the CI pipelines run only against the official community distributions of WireMock.\nIt may work for custom builds and other distributions.\nShould there be any issues, contact their vendors/maintainers.\n\n## Usage\n\nLaunch a standalone Docker instance:\n\n```shell\ndocker run -it --rm -p 8080:8080 wiremock/wiremock\n```\n\nConnect to it using the client library:\n\n```go\npackage main\n\nimport (\n    \"net/http\"\n    \"testing\"\n\n    \"github.com/wiremock/go-wiremock\"\n)\n\nfunc TestSome(t *testing.T) {\n    wiremockClient := wiremock.NewClient(\"http://0.0.0.0:8080\")\n    defer wiremockClient.Reset()\n\n    // stubbing POST http://0.0.0.0:8080/example\n    wiremockClient.StubFor(wiremock.Post(wiremock.URLPathEqualTo(\"/example\")).\n        WithQueryParam(\"firstName\", wiremock.EqualTo(\"John\")).\n        WithQueryParam(\"lastName\", wiremock.NotMatching(\"Black\")).\n        WithBodyPattern(wiremock.EqualToJson(`{\"meta\": \"information\"}`)).\n        WithHeader(\"x-session\", wiremock.Matching(\"^\\\\S+fingerprint\\\\S+$\")).\n        WithBearerToken(wiremock.StartsWith(\"token\")).\n        WillReturnResponse(\n            wiremock.NewResponse().\n                WithJSONBody(map[string]interface{}{\n                    \"code\":   400,\n                    \"detail\": \"detail\",\n                }).\n                WithHeader(\"Content-Type\", \"application/json\").\n                WithStatus(http.StatusBadRequest),\n        ).\n        AtPriority(1))\n\n    // scenario\n    defer wiremockClient.ResetAllScenarios()\n    wiremockClient.StubFor(wiremock.Get(wiremock.URLPathEqualTo(\"/status\")).\n        WillReturnResponse(\n            wiremock.NewResponse().\n                WithJSONBody(map[string]interface{}{\n                    \"status\": nil,\n                }).\n                WithHeader(\"Content-Type\", \"application/json\").\n                WithStatus(http.StatusOK),\n        ).\n        InScenario(\"Set status\").\n        WhenScenarioStateIs(wiremock.ScenarioStateStarted))\n\n    wiremockClient.StubFor(wiremock.Post(wiremock.URLPathEqualTo(\"/state\")).\n        WithBodyPattern(wiremock.EqualToJson(`{\"status\": \"started\"}`)).\n        InScenario(\"Set status\").\n        WillSetStateTo(\"Status started\"))\n\n    statusStub := wiremock.Get(wiremock.URLPathEqualTo(\"/status\")).\n        WillReturnResponse(\n            wiremock.NewResponse().\n                WithJSONBody(map[string]interface{}{\n                    \"status\": \"started\",\n                }).\n                WithHeader(\"Content-Type\", \"application/json\").\n                WithStatus(http.StatusOK),\n        ).\n        InScenario(\"Set status\").\n        WhenScenarioStateIs(\"Status started\")\n    wiremockClient.StubFor(statusStub)\n\n    //testing code...\n\n    verifyResult, _ := wiremockClient.Verify(statusStub.Request(), 1)\n    if !verifyResult {\n        //...\n    }\n\n    wiremockClient.DeleteStub(statusStub)\n}\n```\n\n## Support for Authentication Schemes\n\nThe library provides support for common authentication schemes, i.e.: Basic Authentication, API Token Authentication, Bearer Authentication, Digest Access Authentication.\nAll of them are equivalent to manually specifying the \"Authorization\" header value with the appropriate prefix.\nE.g. `WithBearerToken(wiremock.EqualTo(\"token123\")).` works the same as `WithHeader(\"Authorization\", wiremock.EqualTo(\"Bearer token123\")).`.\n\n### Example of usage\n\n```go\n\nbasicAuthStub := wiremock.Get(wiremock.URLPathEqualTo(\"/basic\")).\n    WithBasicAuth(\"username\", \"password\"). // same as: WithHeader(\"Authorization\", wiremock.EqualTo(\"Basic dXNlcm5hbWU6cGFzc3dvcmQ=\")).\n    WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))\n\nbearerTokenStub := wiremock.Get(wiremock.URLPathEqualTo(\"/bearer\")).\n    WithBearerToken(wiremock.Matching(\"^\\\\S+abc\\\\S+$\")). // same as: WithHeader(\"Authorization\", wiremock.Matching(\"^Bearer \\\\S+abc\\\\S+$\")).\n    WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))\n\napiTokenStub := wiremock.Get(wiremock.URLPathEqualTo(\"/token\")).\n    WithAuthToken(wiremock.StartsWith(\"myToken123\")). // same as: WithHeader(\"Authorization\", wiremock.StartsWith(\"Token myToken123\")).\n    WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))\n\ndigestAuthStub := wiremock.Get(wiremock.URLPathEqualTo(\"/digest\")).\n    WithDigestAuth(wiremock.Contains(\"realm\")). // same as: WithHeader(\"Authorization\", wiremock.StartsWith(\"Digest \").And(Contains(\"realm\"))).\n    WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))\n\n```\n\n## License\n\n[MIT License](./LICENSE)\n\n## See also\n\n- [Golang \u0026 WireMock Solutions page]( https://wiremock.org/docs/solutions/golang/)\n- [WireMock module for Testcontainers Go](https://wiremock.org/docs/solutions/testcontainers/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fgo-wiremock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiremock%2Fgo-wiremock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fgo-wiremock/lists"}