Stringer'ify some structs
This commit is contained in:
1 parent
4aa5e0a97e
commit
18b7110c31
3 files changed
+40
No files matched your search
@@ -34,6 +34,11 @@ const (
|
||||
stResolved entryStatus = iota // resolved
|
||||
)
|
||||
|
||||
var statusToString = map[entryStatus]string{
|
||||
stPending: "pending",
|
||||
stResolved: "resolved",
|
||||
}
|
||||
|
||||
const (
|
||||
CacheNoLocalReplies uint8 = 1 << iota // not found in local network (stored in the cache so we skip another local lookup or some time)
|
||||
)
|
||||
@@ -166,6 +171,19 @@ func (e *cacheEntry) setReply(reply *dns.Msg, ttl int, flags uint8, now time.Tim
|
||||
return (prevValidUntil != e.validUntil)
|
||||
}
|
||||
|
||||
func (e *cacheEntry) String() string {
|
||||
var buf bytes.Buffer
|
||||
q := e.question
|
||||
fmt.Fprintf(&buf, "'%s'[%s]: ", q.Name, dns.TypeToString[q.Qtype])
|
||||
if e.Flags&CacheNoLocalReplies != 0 {
|
||||
fmt.Fprintf(&buf, "neg-local")
|
||||
} else {
|
||||
fmt.Fprintf(&buf, "%s", statusToString[e.Status])
|
||||
}
|
||||
fmt.Fprintf(&buf, "(%d bytes)", e.ReplyLen)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// An entriesPtrHeap is a min-heap of cache entries.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package nameserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/miekg/dns"
|
||||
"math"
|
||||
"net"
|
||||
@@ -52,6 +54,24 @@ func (r Response) Equal(r2 *Response) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (i Response) String() string {
|
||||
var buf bytes.Buffer
|
||||
if i.err != nil {
|
||||
fmt.Fprintf(&buf, "%s", i.err)
|
||||
} else {
|
||||
if len(i.Name()) > 0 {
|
||||
fmt.Fprintf(&buf, "%s", i.Name())
|
||||
}
|
||||
if !i.IP().IsUnspecified() {
|
||||
fmt.Fprintf(&buf, "[%s]", i.IP())
|
||||
}
|
||||
if i.ttl > 0 {
|
||||
fmt.Fprintf(&buf, "(TTL:%d)", i.TTL())
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type responseInfo struct {
|
||||
timeout time.Time // if no answer by this time, give up
|
||||
insistent bool // insistent queries are not removed on the first reply
|
||||
|
||||
@@ -76,6 +76,8 @@ func RunLocalMulticastServer() (*dns.Server, error) {
|
||||
}
|
||||
|
||||
func setup(t *testing.T) (*MDNSClient, *dns.Server, error) {
|
||||
InitDefaultLogging(testing.Verbose())
|
||||
|
||||
server, err := RunLocalMulticastServer()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run test server: %s. No default multicast interface?", err)
|
||||
|
||||
Reference in new issue
Block a user