{"id":17145974,"url":"https://github.com/foxcpp/go-mockdns","last_synced_at":"2025-09-21T03:31:47.770Z","repository":{"id":42370752,"uuid":"219368055","full_name":"foxcpp/go-mockdns","owner":"foxcpp","description":"Boilerplate for testing of code involving DNS lookups, including unholy hacks to redirect net.Lookup* calls.","archived":false,"fork":false,"pushed_at":"2024-06-12T22:46:07.000Z","size":19,"stargazers_count":43,"open_issues_count":6,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-02T07:45:05.812Z","etag":null,"topics":["dns","golang","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/foxcpp.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":"2019-11-03T21:29:10.000Z","updated_at":"2024-10-17T09:14:58.000Z","dependencies_parsed_at":"2023-12-16T00:14:22.866Z","dependency_job_id":"bc1ab8de-da52-4964-866c-d254a05dfc67","html_url":"https://github.com/foxcpp/go-mockdns","commit_stats":{"total_commits":28,"total_committers":5,"mean_commits":5.6,"dds":0.2142857142857143,"last_synced_commit":"964fedcf6894c0d434fffa449d424b206af0cb41"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxcpp%2Fgo-mockdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxcpp%2Fgo-mockdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxcpp%2Fgo-mockdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxcpp%2Fgo-mockdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxcpp","download_url":"https://codeload.github.com/foxcpp/go-mockdns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233707628,"owners_count":18717463,"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":["dns","golang","testing"],"created_at":"2024-10-14T21:07:24.433Z","updated_at":"2025-09-21T03:31:42.518Z","avatar_url":"https://github.com/foxcpp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"go-mockdns\n============\n\n[![Reference](https://godoc.org/github.com/foxcpp/go-mockdns?status.svg)](https://godoc.org/github.com/foxcpp/go-mockdns)\n\nBoilerplate for testing of code involving DNS lookups, including ~~unholy~~\nhacks to redirect `net.Lookup*` calls.\n\nExample\n---------\n\nTrivial mock resolver, for cases where tested code supports custom resolvers:\n```go\nr := mockdns.Resolver{\n    Zones: map[string]mockdns.Zone{\n        \"example.org.\": {\n            A: []string{\"1.2.3.4\"},\n        },\n    },\n}\n\naddrs, err := r.LookupHost(context.Background(), \"example.org\")\nfmt.Println(addrs, err)\n\n// Output:\n// [1.2.3.4] \u003cnil\u003e\n```\n\n~~Unholy~~ hack for cases where it doesn't:\n```go\nsrv, _ := mockdns.NewServer(map[string]mockdns.Zone{\n    \"example.org.\": {\n        A: []string{\"1.2.3.4\"},\n    },\n}, false)\ndefer srv.Close()\n\nsrv.PatchNet(net.DefaultResolver)\ndefer mockdns.UnpatchNet(net.DefaultResolver)\n\naddrs, err := net.LookupHost(\"example.org\")\nfmt.Println(addrs, err)\n\n// Output:\n// [1.2.3.4] \u003cnil\u003e\n```\n\nNote, if you need to replace net.Dial calls and tested code supports custom\nnet.Dial, patch the resolver object inside it instead of net.DefaultResolver.\nIf tested code supports Dialer-like objects - use Resolver itself, it\nimplements Dial and DialContext methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxcpp%2Fgo-mockdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxcpp%2Fgo-mockdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxcpp%2Fgo-mockdns/lists"}