mirror of
https://github.com/hanzoai/dns.git
synced 2026-10-30 18:40:55 +00:00
Nine packages failed. Eight of them for one reason: `go test ./...` ran without
the tags the Makefile ships with (GOTAGS = grpcnotrace metrics), and
luxfi/metric is `//go:build !metrics` — every counter, gauge and histogram is a
no-op unless that tag is set. So metrics, metrics/vars and the kubernetes
object counters were all asserting on numbers that could never move:
RequestCount was not incremented. Before: 0.000000, After: 0.000000
The shipping binary does set it, so this was never a production defect — but a
gate that builds something other than what ships cannot see one either.
The rest were real, and none of them are about metrics:
test/metric_naming_test.go declared a local `type metric` while importing
the package named metric, which every other file here imports too. The
local type is the newcomer; renamed it visitor, for the ast.Visitor it is.
Its BuildFQName call went back to prometheus, which is whose name format is
under test — luxfi/metric has no three-part equivalent, only
AppendNamespace(namespace, name).
Three %q verbs applied to numbers — an MX preference, an Rcode, a SOA
serial. Newer vet rejects them, and `go test` runs vet, so three packages
failed to build without ever reaching a test.
TestImportOrdering walked operator/, which is its own module
(github.com/hanzoai/dns-operator) and imports no coredns, so the
std -> coredns -> 3rd shape it checks for has no middle group to find.
Skipped like pb/ and vendor/ already are, for the same reason.
Eight of the nine pass now. The ninth is test/, where seven metrics
integration tests scrape /metrics and find nothing — the counters record but
are not exposed. That is the other half of the luxfi/metric migration and
wants its own change.
147 lines
3.6 KiB
Go
147 lines
3.6 KiB
Go
package file
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
|
"github.com/coredns/coredns/plugin/test"
|
|
"github.com/coredns/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
func TestLess(t *testing.T) {
|
|
const (
|
|
min = 0
|
|
max = 4294967295
|
|
low = 12345
|
|
high = 4000000000
|
|
)
|
|
|
|
if less(min, max) {
|
|
t.Fatalf("Less: should be false")
|
|
}
|
|
if !less(max, min) {
|
|
t.Fatalf("Less: should be true")
|
|
}
|
|
if !less(high, low) {
|
|
t.Fatalf("Less: should be true")
|
|
}
|
|
if !less(7, 9) {
|
|
t.Fatalf("Less; should be true")
|
|
}
|
|
}
|
|
|
|
type soa struct {
|
|
serial uint32
|
|
}
|
|
|
|
func (s *soa) Handler(w dns.ResponseWriter, req *dns.Msg) {
|
|
m := new(dns.Msg)
|
|
m.SetReply(req)
|
|
switch req.Question[0].Qtype {
|
|
case dns.TypeSOA:
|
|
m.Answer = make([]dns.RR, 1)
|
|
m.Answer[0] = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, s.serial))
|
|
w.WriteMsg(m)
|
|
case dns.TypeAXFR:
|
|
m.Answer = make([]dns.RR, 4)
|
|
m.Answer[0] = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, s.serial))
|
|
m.Answer[1] = test.A(fmt.Sprintf("%s IN A 127.0.0.1", testZone))
|
|
m.Answer[2] = test.A(fmt.Sprintf("%s IN A 127.0.0.1", testZone))
|
|
m.Answer[3] = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, s.serial))
|
|
w.WriteMsg(m)
|
|
}
|
|
}
|
|
|
|
func (s *soa) TransferHandler(w dns.ResponseWriter, req *dns.Msg) {
|
|
m := new(dns.Msg)
|
|
m.SetReply(req)
|
|
m.Answer = make([]dns.RR, 1)
|
|
m.Answer[0] = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, s.serial))
|
|
w.WriteMsg(m)
|
|
}
|
|
|
|
const testZone = "secondary.miek.nl."
|
|
|
|
func TestShouldTransfer(t *testing.T) {
|
|
soa := soa{250}
|
|
|
|
s := dnstest.NewServer(soa.Handler)
|
|
defer s.Close()
|
|
|
|
z := NewZone("testzone", "test")
|
|
z.origin = testZone
|
|
z.TransferFrom = []string{s.Addr}
|
|
|
|
// when we have a nil SOA (initial state)
|
|
should, err := z.shouldTransfer()
|
|
if err != nil {
|
|
t.Fatalf("Unable to run shouldTransfer: %v", err)
|
|
}
|
|
if !should {
|
|
t.Fatalf("ShouldTransfer should return true for serial: %d", soa.serial)
|
|
}
|
|
// Serial smaller
|
|
z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial-1))
|
|
should, err = z.shouldTransfer()
|
|
if err != nil {
|
|
t.Fatalf("Unable to run shouldTransfer: %v", err)
|
|
}
|
|
if !should {
|
|
t.Fatalf("ShouldTransfer should return true for serial: %d", soa.serial-1)
|
|
}
|
|
// Serial equal
|
|
z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial))
|
|
should, err = z.shouldTransfer()
|
|
if err != nil {
|
|
t.Fatalf("Unable to run shouldTransfer: %v", err)
|
|
}
|
|
if should {
|
|
t.Fatalf("ShouldTransfer should return false for serial: %d", soa.serial)
|
|
}
|
|
}
|
|
|
|
func TestTransferIn(t *testing.T) {
|
|
soa := soa{250}
|
|
|
|
s := dnstest.NewServer(soa.Handler)
|
|
defer s.Close()
|
|
|
|
z := new(Zone)
|
|
z.origin = testZone
|
|
z.TransferFrom = []string{s.Addr}
|
|
|
|
if err := z.TransferIn(nil); err != nil {
|
|
t.Fatalf("Unable to run TransferIn: %v", err)
|
|
}
|
|
if z.SOA.String() != fmt.Sprintf("%s 3600 IN SOA bla. bla. 250 0 0 0 0", testZone) {
|
|
t.Fatalf("Unknown SOA transferred")
|
|
}
|
|
}
|
|
|
|
func TestIsNotify(t *testing.T) {
|
|
z := new(Zone)
|
|
z.origin = testZone
|
|
state := newRequest(testZone, dns.TypeSOA)
|
|
// need to set opcode
|
|
state.Req.Opcode = dns.OpcodeNotify
|
|
|
|
z.TransferFrom = []string{"10.240.0.1:53"} // IP from testing/responseWriter
|
|
if !z.isNotify(state) {
|
|
t.Fatal("Should have been valid notify")
|
|
}
|
|
z.TransferFrom = []string{"10.240.0.2:53"}
|
|
if z.isNotify(state) {
|
|
t.Fatal("Should have been invalid notify")
|
|
}
|
|
}
|
|
|
|
func newRequest(_zone string, _qtype uint16) request.Request {
|
|
m := new(dns.Msg)
|
|
m.SetQuestion("example.com.", dns.TypeA)
|
|
m.SetEdns0(4097, true)
|
|
return request.Request{W: &test.ResponseWriter{}, Req: m}
|
|
}
|