MagiTrickle/models/rule_test.go

43 lines
1.2 KiB
Go
Raw Permalink Normal View History

package models
import "testing"
2025-02-15 00:03:02 +03:00
func TestDomain_IsMatch_Domain(t *testing.T) {
rule := &Rule{
2025-02-15 00:03:02 +03:00
Type: "domain",
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")
}
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")
}
}
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")
}
}