DNS sets the DNS zones to emulate for the tested server instance. If it is not called before Run, DNS(nil) call is assumed which makes the mockdns server respond with NXDOMAIN to all queries.
(zones map[string]mockdns.Zone)
| 102 | // If it is not called before Run, DNS(nil) call is assumed which makes the |
| 103 | // mockdns server respond with NXDOMAIN to all queries. |
| 104 | func (t *T) DNS(zones map[string]mockdns.Zone) { |
| 105 | t.Helper() |
| 106 | |
| 107 | if zones == nil { |
| 108 | zones = map[string]mockdns.Zone{} |
| 109 | } |
| 110 | if _, ok := zones["100.97.109.127.in-addr.arpa."]; !ok { |
| 111 | zones["100.97.109.127.in-addr.arpa."] = mockdns.Zone{PTR: []string{"client.maddy.test."}} |
| 112 | } |
| 113 | |
| 114 | if t.dnsServ != nil { |
| 115 | t.Log("NOTE: Multiple DNS calls, replacing the server instance...") |
| 116 | require.NoError(t, t.dnsServ.Close()) |
| 117 | } |
| 118 | |
| 119 | dnsServ, err := mockdns.NewServerWithLogger(zones, t, false) |
| 120 | if err != nil { |
| 121 | t.Fatal("Test configuration failed:", err) |
| 122 | } |
| 123 | dnsServ.Log = t |
| 124 | t.dnsServ = dnsServ |
| 125 | |
| 126 | t.Cleanup(func() { |
| 127 | if t.dnsServ == nil { |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | // Shutdown the DNS server after maddy to make sure it will not spend time |
| 132 | // timing out queries. |
| 133 | if err := t.dnsServ.Close(); err != nil { |
| 134 | t.Log("Unable to stop the DNS server:", err) |
| 135 | } |
| 136 | t.dnsServ = nil |
| 137 | }) |
| 138 | } |
| 139 | |
| 140 | // Port allocates the random TCP port for use by test. It will made accessible |
| 141 | // in the configuration via environment variables with name in the form |