-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_stub.go
41 lines (34 loc) · 818 Bytes
/
dns_stub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package pvl
import (
"fmt"
)
type stubDNSEngine struct {
canned cannedDNS
ok bool
}
// Map from domain to list of records.
// A string "ERROR" will cause an error to be returned.
type cannedDNS map[string]([]string)
func newStubDNSEngine(canned cannedDNS) *stubDNSEngine {
return &stubDNSEngine{
canned: canned,
ok: true,
}
}
func (e *stubDNSEngine) LookupTXT(domain string) ([]string, error) {
defaultres := []string{}
txts, ok := e.canned[domain]
if !ok {
e.ok = false
return defaultres, nil
}
if len(txts) == 1 && txts[0] == "ERROR" {
return defaultres, fmt.Errorf("fake dns error")
}
return txts, nil
}
func (e *stubDNSEngine) IsOk() bool {
return e.ok
}