model.QuotaCarry says what becomes of a quota's use when its rule changes how it counts; the firewall's apply follows it, comparing with the rules in force: per address to a total starts at the addresses' sum, wider groups add up their addresses, and what can't be carried (a total to per address, per source to per destination, finer groups) starts again, with the engine warning quota_restarts on that change. Before, per source to per destination kept the sources' use as destinations', and regrouping left old entries behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
898 B
Go
27 lines
898 B
Go
package model
|
|
|
|
import "testing"
|
|
|
|
func TestQuotaCarry(t *testing.T) {
|
|
rule := func(per string, v4, v6 int) *Rule {
|
|
return &Rule{GroupV4: v4, GroupV6: v6, Quota: &Quota{Bytes: 1, PerSource: per == "src", PerDestination: per == "dst"}}
|
|
}
|
|
for _, c := range []struct {
|
|
old, new *Rule
|
|
want string
|
|
}{
|
|
{rule("", 0, 0), rule("", 0, 0), QuotaKept},
|
|
{rule("src", 0, 0), rule("src", 32, 64), QuotaKept}, // the defaults, written out
|
|
{rule("src", 0, 0), rule("", 0, 0), QuotaSummed},
|
|
{rule("", 0, 0), rule("src", 0, 0), QuotaRestarts},
|
|
{rule("src", 0, 0), rule("dst", 0, 0), QuotaRestarts},
|
|
{rule("src", 0, 0), rule("src", 24, 56), QuotaRegrouped},
|
|
{rule("src", 0, 0), rule("src", 24, 128), QuotaRestarts},
|
|
{nil, rule("src", 0, 0), QuotaKept},
|
|
} {
|
|
if got, _ := QuotaCarry(c.old, c.new); got != c.want {
|
|
t.Errorf("%+v -> %+v: %q, want %q", c.old, c.new, got, c.want)
|
|
}
|
|
}
|
|
}
|