feat: evolve rate-filter to a more generic filter
This commit is contained in:
44
internal/automation/match_test.go
Normal file
44
internal/automation/match_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
package automation
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMatchProxies_NamePattern(t *testing.T) {
|
||||
proxies := []ProxyRef{
|
||||
{OriginalName: "HK 01 | 1.0x", DisplayName: "sub-a | HK 01 | 1.0x", Subscription: "sub-a"},
|
||||
{OriginalName: "HK 02 | 2.5x", DisplayName: "sub-a | HK 02 | 2.5x", Subscription: "sub-a"},
|
||||
{OriginalName: "SG 01 | 0.5x", DisplayName: "sub-b | SG 01 | 0.5x", Subscription: "sub-b"},
|
||||
}
|
||||
|
||||
matched, err := matchProxies(proxies, MatchRule{NamePattern: `^HK \d+`})
|
||||
if err != nil {
|
||||
t.Fatalf("matchProxies() error = %v", err)
|
||||
}
|
||||
if len(matched) != 2 {
|
||||
t.Fatalf("expected 2 matches, got %#v", matched)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchProxies_NamePatternAndOtherDimensionsAreANDed(t *testing.T) {
|
||||
proxies := []ProxyRef{
|
||||
{OriginalName: "HK 01 | 1.0x", DisplayName: "sub-a | HK 01 | 1.0x", Subscription: "sub-a"},
|
||||
{OriginalName: "HK 02 | 2.5x", DisplayName: "sub-b | HK 02 | 2.5x", Subscription: "sub-b"},
|
||||
}
|
||||
|
||||
matched, err := matchProxies(proxies, MatchRule{
|
||||
Subscriptions: []string{"sub-a"},
|
||||
NamePattern: `^HK`,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("matchProxies() error = %v", err)
|
||||
}
|
||||
if len(matched) != 1 || matched[0].DisplayName != "sub-a | HK 01 | 1.0x" {
|
||||
t.Fatalf("unexpected matches: %#v", matched)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchProxies_InvalidNamePattern(t *testing.T) {
|
||||
_, err := matchProxies(nil, MatchRule{NamePattern: "("})
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid name-pattern regexp, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user