From 304632b8cfa40a2bbd5601a21f67aa79bb20cf67 Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Fri, 3 Jul 2026 12:27:39 +0700 Subject: [PATCH] =?UTF-8?q?test(model):=20=D0=BF=D0=BE=D0=BA=D1=80=D1=8B?= =?UTF-8?q?=D1=82=D0=B8=D0=B5=20SRV,=20=D0=BD=D0=B5=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20MX/SRV=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D0=B8=D0=B7=D0=BE=D0=BB=D1=8F?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D1=82=D0=B0=20MX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/model/record_test.go | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/internal/model/record_test.go b/internal/model/record_test.go index 5b760c2..3e9ff8f 100644 --- a/internal/model/record_test.go +++ b/internal/model/record_test.go @@ -37,6 +37,58 @@ func TestEqualMXPriorityAndOrder(t *testing.T) { if a.Equal(c) { t.Fatal("different priority must not be equal") } + + // Isolated case: same value count and same target, only priority differs — + // must fail on priority comparison, not on a length mismatch shortcut. + d := Record{Type: MX, Name: "example.com.", TTL: 3600, Values: []string{"10 mx1.example.com."}} + e := Record{Type: MX, Name: "example.com.", TTL: 3600, Values: []string{"20 mx1.example.com."}} + if d.Equal(e) { + t.Fatal("different MX priority with same target and value count must not be equal") + } +} + +func TestEqualSRVBasic(t *testing.T) { + a := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{ + "10 20 5060 sipserver.example.com.", + "5 10 5061 backup.example.com.", + }} + b := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{ + "5 10 5061 BACKUP.Example.COM.", + "10 20 5060 SIPServer.Example.com.", + }} + if !a.Equal(b) { + t.Fatal("SRV records equal regardless of order and target case") + } + + // Isolated: identical single value except priority differs. + c1 := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{"10 20 5060 sipserver.example.com."}} + c2 := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{"20 20 5060 sipserver.example.com."}} + if c1.Equal(c2) { + t.Fatal("different SRV priority must not be equal") + } + + // Isolated: identical single value except port differs. + d1 := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{"10 20 5060 sipserver.example.com."}} + d2 := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 3600, Values: []string{"10 20 5061 sipserver.example.com."}} + if d1.Equal(d2) { + t.Fatal("different SRV port must not be equal") + } +} + +func TestNormalizeValueIncompleteNoPanic(t *testing.T) { + // MX value missing the target field. + a := Record{Type: MX, Name: "example.com.", TTL: 300, Values: []string{"10"}} + b := Record{Type: MX, Name: "example.com.", TTL: 300, Values: []string{"10"}} + if !a.Equal(b) { + t.Fatal("incomplete MX values with identical content should be equal, not panic") + } + + // SRV value missing port and target fields. + c := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 300, Values: []string{"10 20"}} + d := Record{Type: SRV, Name: "_sip._tcp.example.com.", TTL: 300, Values: []string{"10 20"}} + if !c.Equal(d) { + t.Fatal("incomplete SRV values with identical content should be equal, not panic") + } } func TestEqualTXTCaseSensitive(t *testing.T) {