Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kuritka/go-fake-dns
unit-testing DNS mock tool
https://github.com/kuritka/go-fake-dns
Last synced: 24 days ago
JSON representation
unit-testing DNS mock tool
- Host: GitHub
- URL: https://github.com/kuritka/go-fake-dns
- Owner: kuritka
- License: mit
- Created: 2021-05-16T20:13:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-25T10:08:02.000Z (over 3 years ago)
- Last Synced: 2024-10-11T11:21:20.254Z (about 1 month ago)
- Language: Go
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fake-dns
unit-testing DNS mock tool## Usage
The test below set FakeDNS, run listener on port `8853` and run test against it.```go
package exdnsimport (
"net"
"testing""github.com/miekg/dns"
"github.com/stretchr/testify/require"
)func TestMock(t *testing.T) {
NewDNSMock(t, DNSMockSettings{
Port: 8853,
EdgeDNSZoneFQDN: "example.com.",
DNSZoneFQDN: "cloud.example.com.",
}).
AddNSRecord("blah.cloud.example.com.","gslb-ns-us-cloud.example.com.").
AddNSRecord("blah.cloud.example.com.","gslb-ns-uk-cloud.example.com.").
AddNSRecord("blah.cloud.example.com.","gslb-ns-eu-cloud.example.com.").
AddTXTRecord("First", "Second", "Banana").
AddTXTRecord("White", "Red", "Purple").
AddARecord("blah.cloud.example.com.",net.IPv4(192,168,0,5)).
Start().
RunTestFunc(func() {
g := new(dns.Msg)
//g.SetQuestion("blah.cloud.example.com.", dns.TypeA)
g.SetQuestion("blah.cloud.example.com.", dns.TypeNS)
a, err := dns.Exchange(g, "localhost:8853")
require.NoError(t, err)
require.NotEmpty(t, a.Answer)
for _, A := range a.Answer {
t.Log(A.String())
}
})
}//=== RUN TestMock
//fake DNS listening on port 8853
//dns_server_test.go:32: blah.cloud.example.com. 0 IN NS gslb-ns-us-cloud.example.com.
//dns_server_test.go:32: blah.cloud.example.com. 0 IN NS gslb-ns-uk-cloud.example.com.
//dns_server_test.go:32: blah.cloud.example.com. 0 IN NS gslb-ns-eu-cloud.example.com.
//--- PASS: TestMock (0.00s)
```