Download this file
| 1 | package docs |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "net" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | // TestKeymailDiscoveryStaysInProcess: every unforced POST /signin |
| 12 | // classifies its address (rastrillo/auth's Keymail discovery), so this |
| 13 | // package's tests — TestSigninNeverWaitsForTheMailer's timing above all |
| 14 | // — must not ask the real network whether a domain runs Keymail. With |
| 15 | // keymailtest installed (TestMain) every query is answered NXDOMAIN |
| 16 | // in-process, so even example.com, which public DNS resolves, must not. |
| 17 | func TestKeymailDiscoveryStaysInProcess(t *testing.T) { |
| 18 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 19 | defer cancel() |
| 20 | addrs, err := net.DefaultResolver.LookupHost(ctx, "example.com") |
| 21 | var dnsErr *net.DNSError |
| 22 | if !errors.As(err, &dnsErr) || !dnsErr.IsNotFound { |
| 23 | t.Fatalf("LookupHost(example.com) = %v, %v; want NXDOMAIN from keymailtest's in-process resolver", addrs, err) |
| 24 | } |
| 25 | } |
| 26 | |