2025-02-08 06:23:36 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2025-02-15 00:03:02 +03:00
|
|
|
func TestDomain_IsMatch_Domain(t *testing.T) {
|
2025-02-08 06:23:36 +03:00
|
|
|
rule := &Rule{
|
2025-02-15 00:03:02 +03:00
|
|
|
Type: "domain",
|
2025-02-08 06:23:36 +03:00
|
|
|
Rule: "example.com",
|
|
|
|
}
|
|
|
|
if !rule.IsMatch("example.com") {
|
2025-02-15 00:03:02 +03:00
|
|
|
t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"example.com\") returns false")
|
2025-02-08 06:23:36 +03:00
|
|
|
}
|
|
|
|
if rule.IsMatch("noexample.com") {
|
2025-02-15 00:03:02 +03:00
|
|
|
t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"noexample.com\") returns true")
|
2025-02-08 06:23:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDomain_IsMatch_Wildcard(t *testing.T) {
|
|
|
|
rule := &Rule{
|
|
|
|
Type: "wildcard",
|
|
|
|
Rule: "ex*le.com",
|
|
|
|
}
|
|
|
|
if !rule.IsMatch("example.com") {
|
|
|
|
t.Fatal("&Rule{Type: \"wildcard\", Rule: \"ex*le.com\"}.IsMatch(\"example.com\") returns false")
|
|
|
|
}
|
|
|
|
if rule.IsMatch("noexample.com") {
|
|
|
|
t.Fatal("&Rule{Type: \"wildcard\", Rule: \"ex*le.com\"}.IsMatch(\"noexample.com\") returns true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDomain_IsMatch_RegEx(t *testing.T) {
|
|
|
|
rule := &Rule{
|
|
|
|
Type: "regex",
|
|
|
|
Rule: "^ex[apm]{3}le.com$",
|
|
|
|
}
|
|
|
|
if !rule.IsMatch("example.com") {
|
|
|
|
t.Fatal("&Rule{Type: \"regex\", Rule: \"^ex[apm]{3}le.com$\"}.IsMatch(\"example.com\") returns false")
|
|
|
|
}
|
|
|
|
if rule.IsMatch("noexample.com") {
|
|
|
|
t.Fatal("&Rule{Type: \"regex\", Rule: \"^ex[apm]{3}le.com$\"}.IsMatch(\"noexample.com\") returns true")
|
|
|
|
}
|
|
|
|
}
|