From 965b4e67185df570d3b7529497d5ca8da5a66fd9 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 00:03:02 +0300 Subject: [PATCH] fix tests --- models/rule_test.go | 8 ++++---- records/records_test.go | 29 +++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/models/rule_test.go b/models/rule_test.go index e83c9f2..589fcb7 100644 --- a/models/rule_test.go +++ b/models/rule_test.go @@ -2,16 +2,16 @@ package models import "testing" -func TestDomain_IsMatch_Plaintext(t *testing.T) { +func TestDomain_IsMatch_Domain(t *testing.T) { rule := &Rule{ - Type: "plaintext", + Type: "domain", Rule: "example.com", } if !rule.IsMatch("example.com") { - t.Fatal("&Rule{Type: \"plaintext\", Rule: \"example.com\"}.IsMatch(\"example.com\") returns false") + t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"example.com\") returns false") } if rule.IsMatch("noexample.com") { - t.Fatal("&Rule{Type: \"plaintext\", Rule: \"example.com\"}.IsMatch(\"noexample.com\") returns true") + t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"noexample.com\") returns true") } } diff --git a/records/records_test.go b/records/records_test.go index 90d782e..cbe18ab 100644 --- a/records/records_test.go +++ b/records/records_test.go @@ -9,8 +9,8 @@ import ( func TestLoop(t *testing.T) { r := New() - r.AddCNameRecord("1", "2", time.Minute) - r.AddCNameRecord("2", "1", time.Minute) + r.AddCNameRecord("1", "2", 60) + r.AddCNameRecord("2", "1", 60) if r.GetARecords("1") != nil { t.Fatal("loop detected") } @@ -21,8 +21,8 @@ func TestLoop(t *testing.T) { func TestCName(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, time.Minute) - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 60) + r.AddCNameRecord("gateway.example.com", "example.com", 60) records := r.GetARecords("gateway.example.com") if records == nil { t.Fatal("no records") @@ -34,7 +34,7 @@ func TestCName(t *testing.T) { func TestA(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 60) records := r.GetARecords("example.com") if records == nil { t.Fatal("no records") @@ -46,7 +46,8 @@ func TestA(t *testing.T) { func TestDeprecated(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, -time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 0) + time.Sleep(time.Second) records := r.GetARecords("example.com") if records != nil { t.Fatal("deprecated records") @@ -63,7 +64,7 @@ func TestNotExistedA(t *testing.T) { func TestNotExistedCNameAlias(t *testing.T) { r := New() - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) + r.AddCNameRecord("gateway.example.com", "example.com", 60) records := r.GetARecords("gateway.example.com") if records != nil { t.Fatal("not existed records") @@ -72,8 +73,8 @@ func TestNotExistedCNameAlias(t *testing.T) { func TestReplacing(t *testing.T) { r := New() - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) - r.AddARecord("gateway.example.com", []byte{1, 2, 3, 4}, time.Minute) + r.AddCNameRecord("gateway.example.com", "example.com", 60) + r.AddARecord("gateway.example.com", []byte{1, 2, 3, 4}, 60) records := r.GetARecords("gateway.example.com") if bytes.Compare(records[0].Address, []byte{1, 2, 3, 4}) != 0 { t.Fatal("mismatch") @@ -82,11 +83,11 @@ func TestReplacing(t *testing.T) { func TestAliases(t *testing.T) { r := New() - r.AddARecord("1", []byte{1, 2, 3, 4}, time.Minute) - r.AddCNameRecord("2", "1", time.Minute) - r.AddCNameRecord("3", "2", time.Minute) - r.AddCNameRecord("4", "2", time.Minute) - r.AddCNameRecord("5", "1", time.Minute) + r.AddARecord("1", []byte{1, 2, 3, 4}, 60) + r.AddCNameRecord("2", "1", 60) + r.AddCNameRecord("3", "2", 60) + r.AddCNameRecord("4", "2", 60) + r.AddCNameRecord("5", "1", 60) aliases := r.GetAliases("1") if aliases == nil { t.Fatal("no aliases")