{"id":20757636,"url":"https://github.com/dodevops/golang-handlerinspector","last_synced_at":"2026-04-22T01:31:50.411Z","repository":{"id":213677084,"uuid":"734660782","full_name":"dodevops/golang-handlerinspector","owner":"dodevops","description":"A tool to create http.Handler values using the builder pattern with an included inspector interface for http tests.","archived":false,"fork":false,"pushed_at":"2023-12-22T09:28:41.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-26T12:53:11.182Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dodevops.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":"2023-12-22T09:10:42.000Z","updated_at":"2023-12-22T09:13:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b823173-8f3c-4c82-a1e3-e47798627f36","html_url":"https://github.com/dodevops/golang-handlerinspector","commit_stats":null,"previous_names":["dodevops/golang-handlerinspector"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dodevops/golang-handlerinspector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodevops%2Fgolang-handlerinspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodevops%2Fgolang-handlerinspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodevops%2Fgolang-handlerinspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodevops%2Fgolang-handlerinspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dodevops","download_url":"https://codeload.github.com/dodevops/golang-handlerinspector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodevops%2Fgolang-handlerinspector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32117341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"ssl_error","status_checked_at":"2026-04-22T00:30:22.894Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-17T09:43:27.490Z","updated_at":"2026-04-22T01:31:50.394Z","avatar_url":"https://github.com/dodevops.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Handler Inspector\n\nA tool to create http.Handler values using the builder pattern with an included inspector interface for http tests.\n\n## Installation\n\nUse\n\n    go get github.com/dodevops/golang-handlerinspector@latest\n\nto install and require the module.\n\n## Usage\n\n### Building http.Handler objects\n\nThis module includes a tool to create http.Handler objects using the \n[builder pattern](https://refactoring.guru/design-patterns/builder). The returned object will handle http requests\nusing a set of rules. Each rule is tested against a list of conditions. If all these conditions match, the response\nis generated.\n\nExample:\n\n```go\nbuilder.NewBuilder().\n    WithRule(\n        handlerinspector.NewRule(\"test-endpoint\").\n            WithCondition(handlerinspector.HasPath(\"/api/endpoint\")).\n            WithCondition(handlerinspector.HasMethod(\"GET\")).\n            WithCondition(handlerinspector.HasHeader(\"Authorization\", \"Bearer TESTTOKEN\")).\n            ReturnBody(\"[]\").\n            ReturnHeader(\"Content-Type\", \"application/json\").\n            Build(),\n    )\n```\n\n### Inspecting the generated handler\n\nIn a test context using [httptest's server type](https://pkg.go.dev/net/http/httptest#Server), the supplied Inspector\ntype can be used to inspect the calls to the previously generated http.Handler and use asserts on it.\n\nExample:\n\n```go\nh := builder.NewBuilder().\n    WithRule(\n        handlerinspector.NewRule(\"test-endpoint\").\n            WithCondition(handlerinspector.HasPath(\"/api/endpoint\")).\n            WithCondition(handlerinspector.HasMethod(\"GET\")).\n            WithCondition(handlerinspector.HasHeader(\"Authorization\", \"Bearer TESTTOKEN\")).\n            ReturnBody(\"[]\").\n            ReturnHeader(\"Content-Type\", \"application/json\").\n            Build(),\n    )\ns := httptest.NewServer(h.Build())\ndefer s.Close()\n\n// (...)\n\ni := inspector.NewInspector(h)\nassert.Equal(t, i.Failed(), false)\nassert.Equal(t, i.AllWereCalled(), true)\n```\n\n## Motivation\n\nWhile creating a test suite for our [vmware-rest-proxy](https://github.com/dodevops/vmware-rest-proxy) we were looking\nfor a nice mock server implementation only to find it in a Golang core package, which was a pleasant suprise.\n\nHowever, creating http.Handlers for it and especially testing them was a bit of a hassle, and we didn't find any easy\ntool to achieve it.\n\nThus, here's Handler Inspector. It's currently designed to meet our needs for the vmware-rest-proxy, but can easily\nbe extended if other needs arise.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdodevops%2Fgolang-handlerinspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdodevops%2Fgolang-handlerinspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdodevops%2Fgolang-handlerinspector/lists"}