coredns/plugin/pkg/edns/edns_test.go
Miek Gieben 22c0b30d5f presubmit: Check errorf as well (#1845)
Uppercase all these test errors as well. And extend the presubmit to
check for these in the future. Also do a slightly smarter grep to only
get t.<something>. as (because dump regexp) this also grep over non test
files.
2018-06-02 11:48:39 -07:00

37 lines
607 B
Go

package edns
import (
"testing"
"github.com/miekg/dns"
)
func TestVersion(t *testing.T) {
m := ednsMsg()
m.Extra[0].(*dns.OPT).SetVersion(2)
_, err := Version(m)
if err == nil {
t.Errorf("Expected wrong version, but got OK")
}
}
func TestVersionNoEdns(t *testing.T) {
m := ednsMsg()
m.Extra = nil
_, err := Version(m)
if err != nil {
t.Errorf("Expected no error, but got one: %s", err)
}
}
func ednsMsg() *dns.Msg {
m := new(dns.Msg)
m.SetQuestion("example.com.", dns.TypeA)
o := new(dns.OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
m.Extra = append(m.Extra, o)
return m
}