aboutsummaryrefslogtreecommitdiff
path: root/middleware/edns_test.go
blob: 7b4e6fc66282d9e45008817e587c84852ed78710 (plain) (blame)
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
package middleware

import (
	"testing"

	"github.com/miekg/dns"
)

func TestEdns0Version(t *testing.T) {
	m := ednsMsg()
	m.Extra[0].(*dns.OPT).SetVersion(2)

	_, err := Edns0Version(m)
	if err == nil {
		t.Errorf("expected wrong version, but got OK")
	}
}

func TestEdns0VersionNoEdns(t *testing.T) {
	m := ednsMsg()
	m.Extra = nil

	_, err := Edns0Version(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
}