parent
292c925c9f
commit
f5fe400c53
|
@ -31,7 +31,7 @@ func TestClientSync(t *testing.T) {
|
|||
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
|
||||
|
||||
if r != nil && r.Rcode != RcodeSuccess {
|
||||
t.Log("Failed to get an valid answer")
|
||||
t.Log("failed to get an valid answer")
|
||||
t.Fail()
|
||||
t.Logf("%v\n", r)
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func TestClientEDNS0(t *testing.T) {
|
|||
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
|
||||
|
||||
if r != nil && r.Rcode != RcodeSuccess {
|
||||
t.Log("Failed to get an valid answer")
|
||||
t.Log("failed to get an valid answer")
|
||||
t.Fail()
|
||||
t.Logf("%v\n", r)
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ Loop:
|
|||
first = rtt
|
||||
} else {
|
||||
if first != rtt {
|
||||
t.Log("All rtt should be equal")
|
||||
t.Log("all rtts should be equal")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +101,12 @@ func TestClientTsigAXFR(t *testing.T) {
|
|||
tr.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||
|
||||
if a, err := tr.In(m, "176.58.119.54:53"); err != nil {
|
||||
t.Log("Failed to setup axfr: " + err.Error())
|
||||
t.Log("failed to setup axfr: " + err.Error())
|
||||
t.Fatal()
|
||||
} else {
|
||||
for ex := range a {
|
||||
if ex.Error != nil {
|
||||
t.Logf("Error %s\n", ex.Error.Error())
|
||||
t.Logf("error %s\n", ex.Error.Error())
|
||||
t.Fail()
|
||||
break
|
||||
}
|
||||
|
|
42
dns_test.go
42
dns_test.go
|
@ -21,12 +21,12 @@ func TestPackUnpack(t *testing.T) {
|
|||
out.Answer[0] = key
|
||||
msg, err := out.Pack()
|
||||
if err != nil {
|
||||
t.Log("Failed to pack msg with DNSKEY")
|
||||
t.Log("failed to pack msg with DNSKEY")
|
||||
t.Fail()
|
||||
}
|
||||
in := new(Msg)
|
||||
if in.Unpack(msg) != nil {
|
||||
t.Log("Failed to unpack msg with DNSKEY")
|
||||
t.Log("failed to unpack msg with DNSKEY")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
|
@ -39,12 +39,12 @@ func TestPackUnpack(t *testing.T) {
|
|||
out.Answer[0] = sig
|
||||
msg, err = out.Pack()
|
||||
if err != nil {
|
||||
t.Log("Failed to pack msg with RRSIG")
|
||||
t.Log("failed to pack msg with RRSIG")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if in.Unpack(msg) != nil {
|
||||
t.Log("Failed to unpack msg with RRSIG")
|
||||
t.Log("failed to unpack msg with RRSIG")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func TestPackUnpack3(t *testing.T) {
|
|||
m.Answer[0] = rr
|
||||
b, err := m.Pack()
|
||||
if err != nil {
|
||||
t.Log("Packing failed: " + err.Error())
|
||||
t.Log("packing failed: " + err.Error())
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func TestPackUnpack3(t *testing.T) {
|
|||
var unpackMsg Msg
|
||||
err = unpackMsg.Unpack(b)
|
||||
if err != nil {
|
||||
t.Log("UnPacking failed")
|
||||
t.Log("unpacking failed")
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
|
@ -146,12 +146,12 @@ func TestPack(t *testing.T) {
|
|||
for _, r := range rr {
|
||||
m.Answer[0], err = NewRR(r)
|
||||
if err != nil {
|
||||
t.Logf("Failed to create RR: %s\n", err.Error())
|
||||
t.Logf("failed to create RR: %s\n", err.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
if _, err := m.Pack(); err != nil {
|
||||
t.Logf("Packing failed: %s\n", err.Error())
|
||||
t.Logf("packing failed: %s\n", err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -164,19 +164,19 @@ func TestPack(t *testing.T) {
|
|||
// This crashes due to the fact the a.ntpns.org isn't a FQDN
|
||||
// How to recover() from a remove panic()?
|
||||
if _, err := x.Pack(); err == nil {
|
||||
t.Log("Packing should fail")
|
||||
t.Log("packing should fail")
|
||||
t.Fail()
|
||||
}
|
||||
x.Answer = make([]RR, 1)
|
||||
x.Answer[0], err = NewRR(rr[0])
|
||||
if _, err := x.Pack(); err == nil {
|
||||
t.Log("Packing should fail")
|
||||
t.Log("packing should fail")
|
||||
t.Fail()
|
||||
}
|
||||
x.Question = make([]Question, 1)
|
||||
x.Question[0] = Question{";sd#eddddséâèµââ
â¥âxzztsestxssweewwsssstx@s@Zåµe@cn.pool.ntp.org.", TypeA, ClassINET}
|
||||
if _, err := x.Pack(); err == nil {
|
||||
t.Log("Packing should fail")
|
||||
t.Log("packing should fail")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -190,11 +190,11 @@ func TestPackNAPTR(t *testing.T) {
|
|||
rr, _ := NewRR(n)
|
||||
msg := make([]byte, rr.len())
|
||||
if off, err := PackRR(rr, msg, 0, nil, false); err != nil {
|
||||
t.Logf("Packing failed: %s", err.Error())
|
||||
t.Logf("Length %d, need more than %d\n", rr.len(), off)
|
||||
t.Logf("packing failed: %s", err.Error())
|
||||
t.Logf("length %d, need more than %d\n", rr.len(), off)
|
||||
t.Fail()
|
||||
} else {
|
||||
t.Logf("Buf size needed: %d\n", off)
|
||||
t.Logf("buf size needed: %d\n", off)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ func TestCompressLength(t *testing.T) {
|
|||
ul := m.Len()
|
||||
m.Compress = true
|
||||
if ul != m.Len() {
|
||||
t.Fatalf("Should be equal")
|
||||
t.Fatalf("should be equal")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ func TestMsgCompressLength(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
if predicted < len(buf) {
|
||||
t.Errorf("Predicted compressed length is wrong: predicted %s (len=%d) %d, actual %d\n",
|
||||
t.Errorf("predicted compressed length is wrong: predicted %s (len=%d) %d, actual %d\n",
|
||||
msg.Question[0].Name, len(msg.Answer), predicted, len(buf))
|
||||
t.Fail()
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ func TestMsgLength(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
if predicted < len(buf) {
|
||||
t.Errorf("Predicted length is wrong: predicted %s (len=%d), actual %d\n",
|
||||
t.Errorf("predicted length is wrong: predicted %s (len=%d), actual %d\n",
|
||||
msg.Question[0].Name, predicted, len(buf))
|
||||
t.Fail()
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ func TestNoRdataPack(t *testing.T) {
|
|||
*r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600}
|
||||
_, e := PackRR(r, data, 0, nil, false)
|
||||
if e != nil {
|
||||
t.Logf("Failed to pack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
|
||||
t.Logf("failed to pack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ func TestNoRdataUnpack(t *testing.T) {
|
|||
}
|
||||
rr, _, e := UnpackRR(data[:off], 0)
|
||||
if e != nil {
|
||||
t.Logf("Failed to unpack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
|
||||
t.Logf("failed to unpack RR with zero rdata: %s: %s\n", TypeToString[typ], e.Error())
|
||||
t.Fail()
|
||||
}
|
||||
t.Logf("%s\n", rr)
|
||||
|
@ -472,11 +472,11 @@ func TestRdataOverflow(t *testing.T) {
|
|||
rr.Rdata = hex.EncodeToString(make([]byte, 0xFFFF))
|
||||
buf := make([]byte, 0xFFFF*2)
|
||||
if _, err := PackRR(rr, buf, 0, nil, false); err != nil {
|
||||
t.Fatalf("Maximum size rrdata pack failed: %v", err)
|
||||
t.Fatalf("maximum size rrdata pack failed: %v", err)
|
||||
}
|
||||
rr.Rdata += "00"
|
||||
if _, err := PackRR(rr, buf, 0, nil, false); err != ErrRdata {
|
||||
t.Fatalf("Oversize rrdata pack didn't return ErrRdata - instead: %v", err)
|
||||
t.Fatalf("oversize rrdata pack didn't return ErrRdata - instead: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestSplit(t *testing.T) {
|
|||
}
|
||||
for s, i := range splitter {
|
||||
if x := len(Split(s)); x != i {
|
||||
t.Logf("Labels should be %d, got %d: %s %v\n", i, x, s, Split(s))
|
||||
t.Logf("labels should be %d, got %d: %s %v\n", i, x, s, Split(s))
|
||||
t.Fail()
|
||||
} else {
|
||||
t.Logf("%s %v\n", s, Split(s))
|
||||
|
@ -82,12 +82,12 @@ func TestSplit2(t *testing.T) {
|
|||
switch len(i) {
|
||||
case 1:
|
||||
if x[0] != i[0] {
|
||||
t.Logf("Labels should be %v, got %v: %s\n", i, x, s)
|
||||
t.Logf("labels should be %v, got %v: %s\n", i, x, s)
|
||||
t.Fail()
|
||||
}
|
||||
default:
|
||||
if x[0] != i[0] || x[1] != i[1] || x[2] != i[2] {
|
||||
t.Logf("Labels should be %v, got %v: %s\n", i, x, s)
|
||||
t.Logf("labels should be %v, got %v: %s\n", i, x, s)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func TestPrevLabel(t *testing.T) {
|
|||
for s, i := range prever {
|
||||
x, ok := PrevLabel(s.string, s.int)
|
||||
if i != x {
|
||||
t.Logf("Label should be %d, got %d, %t: preving %d, %s\n", i, x, ok, s.int, s.string)
|
||||
t.Logf("label should be %d, got %d, %t: preving %d, %s\n", i, x, ok, s.int, s.string)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
210
parse_test.go
210
parse_test.go
|
@ -23,18 +23,18 @@ func TestDotInName(t *testing.T) {
|
|||
PackDomainName("aa\\.bb.nl.", buf, 0, nil, false)
|
||||
// index 3 must be a real dot
|
||||
if buf[3] != '.' {
|
||||
t.Log("Dot should be a real dot")
|
||||
t.Log("dot should be a real dot")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if buf[6] != 2 {
|
||||
t.Log("This must have the value 2")
|
||||
t.Log("this must have the value 2")
|
||||
t.Fail()
|
||||
}
|
||||
dom, _, _ := UnpackDomainName(buf, 0)
|
||||
// printing it should yield the backspace again
|
||||
if dom != "aa\\.bb.nl." {
|
||||
t.Log("Dot should have been escaped: " + dom)
|
||||
t.Log("dot should have been escaped: " + dom)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ func TestDotLastInLabel(t *testing.T) {
|
|||
buf := make([]byte, 20)
|
||||
_, err := PackDomainName(sample, buf, 0, nil, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error packing domain: %s", err)
|
||||
t.Fatalf("unexpected error packing domain: %s", err)
|
||||
}
|
||||
dom, _, _ := UnpackDomainName(buf, 0)
|
||||
if dom != sample {
|
||||
t.Fatalf("Unpacked domain `%s' doesn't match packed domain", dom)
|
||||
t.Fatalf("unpacked domain `%s' doesn't match packed domain", dom)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,17 +57,17 @@ func TestTooLongDomainName(t *testing.T) {
|
|||
dom := l + l + l + l + l + l + l
|
||||
_, e := NewRR(dom + " IN A 127.0.0.1")
|
||||
if e == nil {
|
||||
t.Log("Should be too long")
|
||||
t.Log("should be too long")
|
||||
t.Fail()
|
||||
} else {
|
||||
t.Logf("Error is %s", e.Error())
|
||||
t.Logf("error is %s", e.Error())
|
||||
}
|
||||
_, e = NewRR("..com. IN A 127.0.0.1")
|
||||
if e == nil {
|
||||
t.Log("Should fail")
|
||||
t.Log("should fail")
|
||||
t.Fail()
|
||||
} else {
|
||||
t.Logf("Error is %s", e.Error())
|
||||
t.Logf("error is %s", e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,18 +79,18 @@ func TestDomainName(t *testing.T) {
|
|||
|
||||
for _, ts := range tests {
|
||||
if _, err := PackDomainName(ts, dbuff, 0, nil, false); err != nil {
|
||||
t.Log("Not a valid domain name")
|
||||
t.Log("not a valid domain name")
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
n, _, err := UnpackDomainName(dbuff, 0)
|
||||
if err != nil {
|
||||
t.Log("Failed to unpack packed domain name")
|
||||
t.Log("failed to unpack packed domain name")
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
if ts != n {
|
||||
t.Logf("Must be equal: in: %s, out: %s\n", ts, n)
|
||||
t.Logf("must be equal: in: %s, out: %s\n", ts, n)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -120,18 +120,18 @@ func TestDomainNameAndTXTEscapes(t *testing.T) {
|
|||
}
|
||||
repacked := make([]byte, len(rrbytes))
|
||||
if _, err := PackRR(rr2, repacked, 0, nil, false); err != nil {
|
||||
t.Logf("Error packing parsed RR: %v", err)
|
||||
t.Logf(" Original Bytes: %v\n", rrbytes)
|
||||
t.Logf("Unpacked Struct: %V\n", rr1)
|
||||
t.Logf(" Parsed Struct: %V\n", rr2)
|
||||
t.Logf("error packing parsed RR: %v", err)
|
||||
t.Logf(" original Bytes: %v\n", rrbytes)
|
||||
t.Logf("unpacked Struct: %V\n", rr1)
|
||||
t.Logf(" parsed Struct: %V\n", rr2)
|
||||
t.Fail()
|
||||
}
|
||||
if !bytes.Equal(repacked, rrbytes) {
|
||||
t.Log("Packed bytes don't match original bytes")
|
||||
t.Logf(" Original bytes: %v", rrbytes)
|
||||
t.Logf(" Packed bytes: %v", repacked)
|
||||
t.Logf("Unpacked struct: %V", rr1)
|
||||
t.Logf(" Parsed struct: %V", rr2)
|
||||
t.Log("packed bytes don't match original bytes")
|
||||
t.Logf(" original bytes: %v", rrbytes)
|
||||
t.Logf(" packed bytes: %v", repacked)
|
||||
t.Logf("unpacked struct: %V", rr1)
|
||||
t.Logf(" parsed struct: %V", rr2)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -176,16 +176,16 @@ func TestDomainQuick(t *testing.T) {
|
|||
buf := make([]byte, 255)
|
||||
off, err := PackDomainName(ds, buf, 0, nil, false)
|
||||
if err != nil {
|
||||
t.Logf("Error packing domain: %s", err.Error())
|
||||
t.Logf(" Bytes: %v\n", db)
|
||||
t.Logf("String: %v\n", ds)
|
||||
t.Logf("error packing domain: %s", err.Error())
|
||||
t.Logf(" bytes: %v\n", db)
|
||||
t.Logf("string: %v\n", ds)
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(db, buf[:off]) {
|
||||
t.Logf("Repacked domain doesn't match original:")
|
||||
t.Logf("Src Bytes: %v", db)
|
||||
t.Logf(" String: %v", ds)
|
||||
t.Logf("Out Bytes: %v", buf[:off])
|
||||
t.Logf("repacked domain doesn't match original:")
|
||||
t.Logf("src bytes: %v", db)
|
||||
t.Logf(" string: %v", ds)
|
||||
t.Logf("out bytes: %v", buf[:off])
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -242,15 +242,15 @@ func TestTXTRRQuick(t *testing.T) {
|
|||
buf := make([]byte, len(rrbytes)*3)
|
||||
off, err := PackRR(rr, buf, 0, nil, false)
|
||||
if err != nil {
|
||||
t.Logf("Pack Error: %s\nRR: %V", err.Error(), rr)
|
||||
t.Logf("pack Error: %s\nRR: %V", err.Error(), rr)
|
||||
return false
|
||||
}
|
||||
buf = buf[:off]
|
||||
if !bytes.Equal(buf, rrbytes) {
|
||||
t.Logf("Packed bytes don't match original bytes")
|
||||
t.Logf("Src Bytes: %v", rrbytes)
|
||||
t.Logf(" Struct: %V", rr)
|
||||
t.Logf("Out Bytes: %v", buf)
|
||||
t.Logf("packed bytes don't match original bytes")
|
||||
t.Logf("src bytes: %v", rrbytes)
|
||||
t.Logf(" struct: %V", rr)
|
||||
t.Logf("oUt bytes: %v", buf)
|
||||
return false
|
||||
}
|
||||
if len(rdata) == 0 {
|
||||
|
@ -260,35 +260,35 @@ func TestTXTRRQuick(t *testing.T) {
|
|||
rrString := rr.String()
|
||||
rr2, err := NewRR(rrString)
|
||||
if err != nil {
|
||||
t.Logf("Error parsing own output: %s", err.Error())
|
||||
t.Logf("Struct: %V", rr)
|
||||
t.Logf("String: %v", rrString)
|
||||
t.Logf("error parsing own output: %s", err.Error())
|
||||
t.Logf("struct: %V", rr)
|
||||
t.Logf("string: %v", rrString)
|
||||
return false
|
||||
}
|
||||
if rr2.String() != rrString {
|
||||
t.Logf("Parsed rr.String() doesn't match original string")
|
||||
t.Logf("Original: %v", rrString)
|
||||
t.Logf(" Parsed: %v", rr2.String())
|
||||
t.Logf("parsed rr.String() doesn't match original string")
|
||||
t.Logf("original: %v", rrString)
|
||||
t.Logf(" parsed: %v", rr2.String())
|
||||
return false
|
||||
}
|
||||
|
||||
buf = make([]byte, len(rrbytes)*3)
|
||||
off, err = PackRR(rr2, buf, 0, nil, false)
|
||||
if err != nil {
|
||||
t.Logf("Error packing parsed rr: %s", err.Error())
|
||||
t.Logf("Unpacked Struct: %V", rr)
|
||||
t.Logf(" String: %v", rrString)
|
||||
t.Logf(" Parsed Struct: %V", rr2)
|
||||
t.Logf("error packing parsed rr: %s", err.Error())
|
||||
t.Logf("unpacked Struct: %V", rr)
|
||||
t.Logf(" string: %v", rrString)
|
||||
t.Logf(" parsed Struct: %V", rr2)
|
||||
return false
|
||||
}
|
||||
buf = buf[:off]
|
||||
if !bytes.Equal(buf, rrbytes) {
|
||||
t.Logf("Parsed packed bytes don't match original bytes")
|
||||
t.Logf(" Source Bytes: %v", rrbytes)
|
||||
t.Logf("Unpacked Struct: %V", rr)
|
||||
t.Logf(" String: %v", rrString)
|
||||
t.Logf(" Parsed Struct: %V", rr2)
|
||||
t.Logf(" Repacked Bytes: %v", buf)
|
||||
t.Logf("parsed packed bytes don't match original bytes")
|
||||
t.Logf(" source bytes: %v", rrbytes)
|
||||
t.Logf("unpacked struct: %V", rr)
|
||||
t.Logf(" string: %v", rrString)
|
||||
t.Logf(" parsed struct: %V", rr2)
|
||||
t.Logf(" repacked bytes: %v", buf)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -317,7 +317,7 @@ func TestParseDirectiveMisc(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ func TestNSEC(t *testing.T) {
|
|||
for i, o := range nsectests {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ func TestParseLOC(t *testing.T) {
|
|||
for i, o := range lt {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ func TestParseDS(t *testing.T) {
|
|||
for i, o := range dt {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ func TestQuotes(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ func TestParseClass(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ func TestBrace(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error() + "\n\t" + i)
|
||||
t.Log("failed to parse RR: " + e.Error() + "\n\t" + i)
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ func TestParseFailure(t *testing.T) {
|
|||
for _, s := range tests {
|
||||
_, err := NewRR(s)
|
||||
if err == nil {
|
||||
t.Logf("Should have triggered an error: \"%s\"", s)
|
||||
t.Logf("should have triggered an error: \"%s\"", s)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -636,17 +636,17 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
|
|||
rvs2.example.com. )`
|
||||
rr, err := NewRR(h)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse RR: %s", err)
|
||||
t.Fatalf("failed to parse RR: %s", err)
|
||||
}
|
||||
t.Logf("RR: %s", rr)
|
||||
msg := new(Msg)
|
||||
msg.Answer = []RR{rr, rr}
|
||||
bytes, err := msg.Pack()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to pack msg: %s", err)
|
||||
t.Fatalf("failed to pack msg: %s", err)
|
||||
}
|
||||
if err := msg.Unpack(bytes); err != nil {
|
||||
t.Fatalf("Failed to unpack msg: %s", err)
|
||||
t.Fatalf("failed to unpack msg: %s", err)
|
||||
}
|
||||
if len(msg.Answer) != 2 {
|
||||
t.Fatalf("2 answers expected: %V", msg)
|
||||
|
@ -659,7 +659,7 @@ b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
|
|||
}
|
||||
for j, s := range []string{"rvs1.example.com.", "rvs2.example.com."} {
|
||||
if rr.RendezvousServers[j] != s {
|
||||
t.Fatalf("Expected server %d of record %d to be %s:\n%V", j, i, s, msg)
|
||||
t.Fatalf("expected server %d of record %d to be %s:\n%V", j, i, s, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ func TestLineNumberError(t *testing.T) {
|
|||
s := "example.com. 1000 SOA master.example.com. admin.example.com. monkey 4294967294 4294967293 4294967295 100"
|
||||
if _, err := NewRR(s); err != nil {
|
||||
if err.Error() != "dns: bad SOA zone parameter: \"monkey\" at line: 1:68" {
|
||||
t.Logf("Not expecting this error: " + err.Error())
|
||||
t.Logf("not expecting this error: " + err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -703,7 +703,7 @@ func TestLineNumberError2(t *testing.T) {
|
|||
} else {
|
||||
if e.Error() != err {
|
||||
t.Logf("%s\n", in)
|
||||
t.Logf("Error should be %s is %s\n", err, e.Error())
|
||||
t.Logf("error should be %s is %s\n", err, e.Error())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ func TestRfc1982(t *testing.T) {
|
|||
|
||||
func TestEmpty(t *testing.T) {
|
||||
for _ = range ParseZone(strings.NewReader(""), "", "") {
|
||||
t.Logf("Should be empty")
|
||||
t.Logf("should be empty")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -818,25 +818,25 @@ func TestSRVPacking(t *testing.T) {
|
|||
|
||||
_, err := msg.Pack()
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't pack %v\n", msg)
|
||||
t.Fatalf("couldn't pack %v\n", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBackslash(t *testing.T) {
|
||||
if r, e := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); e != nil {
|
||||
t.Fatalf("Could not create RR with \\000 in it")
|
||||
t.Fatalf("could not create RR with \\000 in it")
|
||||
} else {
|
||||
t.Logf("Parsed %s\n", r.String())
|
||||
t.Logf("parsed %s\n", r.String())
|
||||
}
|
||||
if r, e := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); e != nil {
|
||||
t.Fatalf("Could not create RR with \\000 in it")
|
||||
t.Fatalf("could not create RR with \\000 in it")
|
||||
} else {
|
||||
t.Logf("Parsed %s\n", r.String())
|
||||
t.Logf("parsed %s\n", r.String())
|
||||
}
|
||||
if r, e := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); e != nil {
|
||||
t.Fatalf("Could not create RR with \\ and \\@ in it")
|
||||
t.Fatalf("could not create RR with \\ and \\@ in it")
|
||||
} else {
|
||||
t.Logf("Parsed %s\n", r.String())
|
||||
t.Logf("parsed %s\n", r.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -858,10 +858,10 @@ func TestILNP(t *testing.T) {
|
|||
for _, t1 := range tests {
|
||||
r, e := NewRR(t1)
|
||||
if e != nil {
|
||||
t.Fatalf("An error occured: %s\n", e.Error())
|
||||
t.Fatalf("an error occured: %s\n", e.Error())
|
||||
} else {
|
||||
if t1 != r.String() {
|
||||
t.Fatalf("Strings should be equal %s %s", t1, r.String())
|
||||
t.Fatalf("strings should be equal %s %s", t1, r.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -880,7 +880,7 @@ func TestNsapGposEidNimloc(t *testing.T) {
|
|||
for i, o := range dt {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -901,7 +901,7 @@ func TestPX(t *testing.T) {
|
|||
for i, o := range dt {
|
||||
rr, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Log("Failed to parse RR: " + e.Error())
|
||||
t.Log("failed to parse RR: " + e.Error())
|
||||
t.Fail()
|
||||
continue
|
||||
}
|
||||
|
@ -957,11 +957,11 @@ func TestEUIxx(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
r, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Logf("Failed to parse %s: %s\n", i, e.Error())
|
||||
t.Logf("failed to parse %s: %s\n", i, e.Error())
|
||||
t.Fail()
|
||||
}
|
||||
if r.String() != o {
|
||||
t.Logf("Want %s, got %s\n", o, r.String())
|
||||
t.Logf("want %s, got %s\n", o, r.String())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -976,11 +976,11 @@ func TestUserRR(t *testing.T) {
|
|||
for i, o := range tests {
|
||||
r, e := NewRR(i)
|
||||
if e != nil {
|
||||
t.Logf("Failed to parse %s: %s\n", i, e.Error())
|
||||
t.Logf("failed to parse %s: %s\n", i, e.Error())
|
||||
t.Fail()
|
||||
}
|
||||
if r.String() != o {
|
||||
t.Logf("Want %s, got %s\n", o, r.String())
|
||||
t.Logf("want %s, got %s\n", o, r.String())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -990,60 +990,60 @@ func TestTXT(t *testing.T) {
|
|||
// Test single entry TXT record
|
||||
rr, err := NewRR(`_raop._tcp.local. 60 IN TXT "single value"`)
|
||||
if err != nil {
|
||||
t.Error("Failed to parse single value TXT record", err)
|
||||
t.Error("failed to parse single value TXT record", err)
|
||||
} else if rr, ok := rr.(*TXT); !ok {
|
||||
t.Error("Wrong type, record should be of type TXT")
|
||||
t.Error("wrong type, record should be of type TXT")
|
||||
} else {
|
||||
if len(rr.Txt) != 1 {
|
||||
t.Error("Bad size of TXT value:", len(rr.Txt))
|
||||
t.Error("bad size of TXT value:", len(rr.Txt))
|
||||
} else if rr.Txt[0] != "single value" {
|
||||
t.Error("Bad single value")
|
||||
t.Error("bad single value")
|
||||
}
|
||||
if rr.String() != `_raop._tcp.local. 60 IN TXT "single value"` {
|
||||
t.Error("Bad representation of TXT record:", rr.String())
|
||||
t.Error("bad representation of TXT record:", rr.String())
|
||||
}
|
||||
if rr.len() != 28+1+12 {
|
||||
t.Error("Bad size of serialized record:", rr.len())
|
||||
t.Error("bad size of serialized record:", rr.len())
|
||||
}
|
||||
}
|
||||
|
||||
// Test multi entries TXT record
|
||||
rr, err = NewRR(`_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"`)
|
||||
if err != nil {
|
||||
t.Error("Failed to parse multi-values TXT record", err)
|
||||
t.Error("failed to parse multi-values TXT record", err)
|
||||
} else if rr, ok := rr.(*TXT); !ok {
|
||||
t.Error("Wrong type, record should be of type TXT")
|
||||
t.Error("wrong type, record should be of type TXT")
|
||||
} else {
|
||||
if len(rr.Txt) != 4 {
|
||||
t.Error("Bad size of TXT multi-value:", len(rr.Txt))
|
||||
t.Error("bad size of TXT multi-value:", len(rr.Txt))
|
||||
} else if rr.Txt[0] != "a=1" || rr.Txt[1] != "b=2" || rr.Txt[2] != "c=3" || rr.Txt[3] != "d=4" {
|
||||
t.Error("Bad values in TXT records")
|
||||
t.Error("bad values in TXT records")
|
||||
}
|
||||
if rr.String() != `_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"` {
|
||||
t.Error("Bad representation of TXT multi value record:", rr.String())
|
||||
t.Error("bad representation of TXT multi value record:", rr.String())
|
||||
}
|
||||
if rr.len() != 28+1+3+1+3+1+3+1+3 {
|
||||
t.Error("Bad size of serialized multi value record:", rr.len())
|
||||
t.Error("bad size of serialized multi value record:", rr.len())
|
||||
}
|
||||
}
|
||||
|
||||
// Test empty-string in TXT record
|
||||
rr, err = NewRR(`_raop._tcp.local. 60 IN TXT ""`)
|
||||
if err != nil {
|
||||
t.Error("Failed to parse empty-string TXT record", err)
|
||||
t.Error("failed to parse empty-string TXT record", err)
|
||||
} else if rr, ok := rr.(*TXT); !ok {
|
||||
t.Error("Wrong type, record should be of type TXT")
|
||||
t.Error("wrong type, record should be of type TXT")
|
||||
} else {
|
||||
if len(rr.Txt) != 1 {
|
||||
t.Error("Bad size of TXT empty-string value:", len(rr.Txt))
|
||||
t.Error("bad size of TXT empty-string value:", len(rr.Txt))
|
||||
} else if rr.Txt[0] != "" {
|
||||
t.Error("Bad value for empty-string TXT record")
|
||||
t.Error("bad value for empty-string TXT record")
|
||||
}
|
||||
if rr.String() != `_raop._tcp.local. 60 IN TXT ""` {
|
||||
t.Error("Bad representation of empty-string TXT record:", rr.String())
|
||||
t.Error("bad representation of empty-string TXT record:", rr.String())
|
||||
}
|
||||
if rr.len() != 28+1 {
|
||||
t.Error("Bad size of serialized record:", rr.len())
|
||||
t.Error("bad size of serialized record:", rr.len())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1051,17 +1051,17 @@ func TestTXT(t *testing.T) {
|
|||
func TestTypeXXXX(t *testing.T) {
|
||||
_, err := NewRR("example.com IN TYPE1234 \\# 4 aabbccdd")
|
||||
if err != nil {
|
||||
t.Logf("Failed to parse TYPE1234 RR: ", err.Error())
|
||||
t.Logf("failed to parse TYPE1234 RR: ", err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
_, err = NewRR("example.com IN TYPE655341 \\# 8 aabbccddaabbccdd")
|
||||
if err == nil {
|
||||
t.Logf("This should not work, for TYPE655341")
|
||||
t.Logf("this should not work, for TYPE655341")
|
||||
t.Fail()
|
||||
}
|
||||
_, err = NewRR("example.com IN TYPE1 \\# 4 0a000001")
|
||||
if err == nil {
|
||||
t.Logf("This should not work")
|
||||
t.Logf("this should not work")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -1069,7 +1069,7 @@ func TestTypeXXXX(t *testing.T) {
|
|||
func TestPTR(t *testing.T) {
|
||||
_, err := NewRR("144.2.0.192.in-addr.arpa. 900 IN PTR ilouse03146p0\\(.example.com.")
|
||||
if err != nil {
|
||||
t.Error("Failed to parse ", err.Error())
|
||||
t.Error("failed to parse ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1087,7 +1087,7 @@ func TestDigit(t *testing.T) {
|
|||
r, e := NewRR(s)
|
||||
buf := make([]byte, 40)
|
||||
if e != nil {
|
||||
t.Fatalf("Failed to parse %s\n", e.Error())
|
||||
t.Fatalf("failed to parse %s\n", e.Error())
|
||||
}
|
||||
PackRR(r, buf, 0, nil, false)
|
||||
t.Logf("%v\n", buf)
|
||||
|
@ -1096,7 +1096,7 @@ func TestDigit(t *testing.T) {
|
|||
}
|
||||
r1, _, _ := UnpackRR(buf, 0)
|
||||
if r1.Header().Ttl != 100 {
|
||||
t.Fatalf("Ttl should %d, is %d", 100, r1.Header().Ttl)
|
||||
t.Fatalf("TTL should %d, is %d", 100, r1.Header().Ttl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1121,7 +1121,7 @@ func TestTxtEqual(t *testing.T) {
|
|||
rr1.Txt = []string{"a\"a", "\"", "b"}
|
||||
rr2, _ := NewRR(rr1.String())
|
||||
if rr1.String() != rr2.String() {
|
||||
t.Logf("These two TXT records should match")
|
||||
t.Logf("these two TXT records should match")
|
||||
t.Logf("\n%s\n%s\n", rr1.String(), rr2.String())
|
||||
t.Fail() // This is not an error, but keep this test.
|
||||
}
|
||||
|
@ -1139,7 +1139,7 @@ func TestTxtLong(t *testing.T) {
|
|||
}
|
||||
str := rr1.String()
|
||||
if len(str) < len(rr1.Txt[0]) {
|
||||
t.Logf("String conversion should just work")
|
||||
t.Logf("string conversion should work")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func TestServing(t *testing.T) {
|
|||
m.SetQuestion("miek.nl.", TypeTXT)
|
||||
r, _, err := c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange miek.nl", err)
|
||||
t.Log("failed to exchange miek.nl", err)
|
||||
t.Fatal()
|
||||
}
|
||||
txt := r.Extra[0].(*TXT).Txt[0]
|
||||
|
@ -59,7 +59,7 @@ func TestServing(t *testing.T) {
|
|||
m.SetQuestion("example.com.", TypeTXT)
|
||||
r, _, err = c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange example.com", err)
|
||||
t.Log("failed to exchange example.com", err)
|
||||
t.Fatal()
|
||||
}
|
||||
txt = r.Extra[0].(*TXT).Txt[0]
|
||||
|
@ -72,7 +72,7 @@ func TestServing(t *testing.T) {
|
|||
m.SetQuestion("eXaMplE.cOm.", TypeTXT)
|
||||
r, _, err = c.Exchange(m, "127.0.0.1:8053")
|
||||
if err != nil {
|
||||
t.Log("Failed to exchange eXaMplE.cOm", err)
|
||||
t.Log("failed to exchange eXaMplE.cOm", err)
|
||||
t.Fail()
|
||||
}
|
||||
txt = r.Extra[0].(*TXT).Txt[0]
|
||||
|
@ -252,7 +252,7 @@ func TestServingLargeResponses(t *testing.T) {
|
|||
M.Unlock()
|
||||
_, _, err := c.Exchange(m, "127.0.0.1:10000")
|
||||
if err != nil {
|
||||
t.Logf("Failed to exchange: %s", err.Error())
|
||||
t.Logf("failed to exchange: %s", err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
// This must fail
|
||||
|
@ -261,14 +261,28 @@ func TestServingLargeResponses(t *testing.T) {
|
|||
M.Unlock()
|
||||
_, _, err = c.Exchange(m, "127.0.0.1:10000")
|
||||
if err == nil {
|
||||
t.Logf("Failed to fail exchange, this should generate packet error")
|
||||
t.Logf("failed to fail exchange, this should generate packet error")
|
||||
t.Fail()
|
||||
}
|
||||
// But this must work again
|
||||
c.UDPSize = 7000
|
||||
_, _, err = c.Exchange(m, "127.0.0.1:10000")
|
||||
if err != nil {
|
||||
t.Logf("Failed to exchange: %s", err.Error())
|
||||
t.Logf("failed to exchange: %s", err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestShutdown(t *testing.T) {
|
||||
server := Server{Addr: ":8053", Net: "udp"}
|
||||
go func() {
|
||||
err := server.ListenAndServe()
|
||||
if err != nil {
|
||||
t.Logf("failed to setup the udp server: %s\n", err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
t.Logf("successfully stopped the server")
|
||||
}()
|
||||
time.Sleep(4e8)
|
||||
server.Shutdown()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue