1package dns 2 3import ( 4 "testing" 5) 6 7func TestAcceptNotify(t *testing.T) { 8 HandleFunc("example.org.", handleNotify) 9 s, addrstr, err := RunLocalUDPServer(":0") 10 if err != nil { 11 t.Fatalf("unable to run test server: %v", err) 12 } 13 defer s.Shutdown() 14 15 m := new(Msg) 16 m.SetNotify("example.org.") 17 // Set a SOA hint in the answer section, this is allowed according to RFC 1996. 18 soa, _ := NewRR("example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2018112827 7200 3600 1209600 3600") 19 m.Answer = []RR{soa} 20 21 c := new(Client) 22 resp, _, err := c.Exchange(m, addrstr) 23 if err != nil { 24 t.Errorf("failed to exchange: %v", err) 25 } 26 if resp.Rcode != RcodeSuccess { 27 t.Errorf("expected %s, got %s", RcodeToString[RcodeSuccess], RcodeToString[resp.Rcode]) 28 } 29} 30 31func handleNotify(w ResponseWriter, req *Msg) { 32 m := new(Msg) 33 m.SetReply(req) 34 w.WriteMsg(m) 35} 36