refactor: use reflect.TypeFor (#7696)

This commit is contained in:
zhetaicheleba
2025-11-20 02:40:18 +09:00
committed by GitHub
parent 614a364458
commit 9989ac5060
6 changed files with 112 additions and 112 deletions

View File

@@ -78,16 +78,16 @@ func TestTtlRewrite(t *testing.T) {
args []string
expectedType reflect.Type
}{
{[]string{"stop", "ttl", "srv1.coredns.rocks", "1"}, reflect.TypeOf(&exactTTLRule{})},
{[]string{"stop", "ttl", "exact", "srv15.coredns.rocks", "15"}, reflect.TypeOf(&exactTTLRule{})},
{[]string{"stop", "ttl", "prefix", "srv30", "30"}, reflect.TypeOf(&prefixTTLRule{})},
{[]string{"stop", "ttl", "suffix", "45.coredns.rocks", "45"}, reflect.TypeOf(&suffixTTLRule{})},
{[]string{"stop", "ttl", "substring", "rv50", "50"}, reflect.TypeOf(&substringTTLRule{})},
{[]string{"stop", "ttl", "regex", `(srv10)\.(coredns)\.(rocks)`, "10"}, reflect.TypeOf(&regexTTLRule{})},
{[]string{"stop", "ttl", "regex", `(srv20)\.(coredns)\.(rocks)`, "20"}, reflect.TypeOf(&regexTTLRule{})},
{[]string{"stop", "ttl", "range.example.com.", "30-300"}, reflect.TypeOf(&exactTTLRule{})},
{[]string{"stop", "ttl", "ceil.example.com.", "-11"}, reflect.TypeOf(&exactTTLRule{})},
{[]string{"stop", "ttl", "floor.example.com.", "5-"}, reflect.TypeOf(&exactTTLRule{})},
{[]string{"stop", "ttl", "srv1.coredns.rocks", "1"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "exact", "srv15.coredns.rocks", "15"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "prefix", "srv30", "30"}, reflect.TypeFor[*prefixTTLRule]()},
{[]string{"stop", "ttl", "suffix", "45.coredns.rocks", "45"}, reflect.TypeFor[*suffixTTLRule]()},
{[]string{"stop", "ttl", "substring", "rv50", "50"}, reflect.TypeFor[*substringTTLRule]()},
{[]string{"stop", "ttl", "regex", `(srv10)\.(coredns)\.(rocks)`, "10"}, reflect.TypeFor[*regexTTLRule]()},
{[]string{"stop", "ttl", "regex", `(srv20)\.(coredns)\.(rocks)`, "20"}, reflect.TypeFor[*regexTTLRule]()},
{[]string{"stop", "ttl", "range.example.com.", "30-300"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "ceil.example.com.", "-11"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "floor.example.com.", "5-"}, reflect.TypeFor[*exactTTLRule]()},
}
for i, r := range ruleset {
rule, err := newRule(r.args...)