mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-11-05 00:50:21 +00:00
Update ddns_test.go
This commit is contained in:
1 parent
ed9f21e4ea
commit
09db8b4361
1 file changed
+29
-18
+29
-18
@@ -3,6 +3,7 @@ package ddns
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/libdns/libdns"
|
"github.com/libdns/libdns"
|
||||||
@@ -24,17 +25,15 @@ func TestSplitDomainSOA(t *testing.T) {
|
|||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
if len(r.Question) > 0 {
|
if len(r.Question) > 0 {
|
||||||
qname := r.Question[0].Name
|
qname := r.Question[0].Name
|
||||||
soa := &dns.SOA{
|
if strings.HasSuffix(qname, "example.co.uk.") || strings.HasSuffix(qname, "example.com.") {
|
||||||
Hdr: dns.RR_Header{Name: qname, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: 300},
|
soa := &dns.SOA{
|
||||||
Ns: "ns.example.com.",
|
Hdr: dns.RR_Header{Name: qname, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: 300},
|
||||||
Mbox: "admin.example.com.",
|
Ns: "ns.example.com.",
|
||||||
Serial: 1,
|
Mbox: "admin.example.com.",
|
||||||
Refresh: 3600,
|
Serial: 1,
|
||||||
Retry: 600,
|
}
|
||||||
Expire: 86400,
|
m.Answer = append(m.Answer, soa)
|
||||||
Minttl: 60,
|
|
||||||
}
|
}
|
||||||
m.Answer = append(m.Answer, soa)
|
|
||||||
}
|
}
|
||||||
_ = w.WriteMsg(m)
|
_ = w.WriteMsg(m)
|
||||||
})
|
})
|
||||||
@@ -149,9 +148,8 @@ func TestIndependentDualStackProcessing(t *testing.T) {
|
|||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
if len(r.Question) > 0 {
|
if len(r.Question) > 0 {
|
||||||
qname := r.Question[0].Name
|
|
||||||
soa := &dns.SOA{
|
soa := &dns.SOA{
|
||||||
Hdr: dns.RR_Header{Name: qname, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: 300},
|
Hdr: dns.RR_Header{Name: r.Question[0].Name, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: 300},
|
||||||
}
|
}
|
||||||
m.Answer = append(m.Answer, soa)
|
m.Answer = append(m.Answer, soa)
|
||||||
}
|
}
|
||||||
@@ -177,8 +175,21 @@ func TestIndependentDualStackProcessing(t *testing.T) {
|
|||||||
t.Fatalf("expected SetRecords to have been called for dual stack updates")
|
t.Fatalf("expected SetRecords to have been called for dual stack updates")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(mockSetter.Records) != 2 {
|
foundIPv4 := false
|
||||||
t.Fatalf("expected 2 records (IPv4 and IPv6) to be set, got %d", len(mockSetter.Records))
|
foundIPv6 := false
|
||||||
|
for _, rec := range mockSetter.Records {
|
||||||
|
if addrRec, ok := rec.(libdns.Address); ok {
|
||||||
|
if addrRec.IP.String() == "1.1.1.1" {
|
||||||
|
foundIPv4 = true
|
||||||
|
}
|
||||||
|
if addrRec.IP.String() == "2001:db8::1" {
|
||||||
|
foundIPv6 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !foundIPv4 || !foundIPv6 {
|
||||||
|
t.Fatalf("expected both IPv4 and IPv6 records to be processed independently, got records: %v", mockSetter.Records)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,11 +215,11 @@ func TestTransientSOAFailureAndRetry(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
defer server.Shutdown()
|
defer server.Shutdown()
|
||||||
|
|
||||||
maxRetries := 3
|
var maxRetries uint64 = 3
|
||||||
provider := &Provider{
|
provider := &Provider{
|
||||||
DDNSProfile: &model.DDNSProfile{
|
DDNSProfile: &model.DDNSProfile{
|
||||||
MaxRetries: uint64(maxRetries),
|
MaxRetries: maxRetries,
|
||||||
Domains: []string{"fail.invalid"},
|
Domains: []string{"fail"},
|
||||||
},
|
},
|
||||||
IPAddrs: &model.IP{IPv4Addr: "1.1.1.1"},
|
IPAddrs: &model.IP{IPv4Addr: "1.1.1.1"},
|
||||||
Setter: &MockSetter{},
|
Setter: &MockSetter{},
|
||||||
@@ -217,7 +228,7 @@ func TestTransientSOAFailureAndRetry(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), DNSServerKey{}, []string{pc.LocalAddr().String()})
|
ctx := context.WithValue(context.Background(), DNSServerKey{}, []string{pc.LocalAddr().String()})
|
||||||
provider.UpdateDomain(ctx)
|
provider.UpdateDomain(ctx)
|
||||||
|
|
||||||
if attempts != maxRetries {
|
if uint64(attempts) != maxRetries {
|
||||||
t.Fatalf("expected exact attempt count of %d, got %d", maxRetries, attempts)
|
t.Fatalf("expected exact attempt count of %d, got %d", maxRetries, attempts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user