package quota import ( "context" "testing" ) type fakeLimits struct { limitBytes int64 configured bool } func (f fakeLimits) LimitBytes(context.Context, string, string) (int64, bool, error) { return f.limitBytes, f.configured, nil } type fakeUsage struct { usedBytes int64 } func (f fakeUsage) UsageBytes(context.Context, string, string) (int64, error) { return f.usedBytes, nil } func TestCheck_UnconfiguredLimitAlwaysAllowed(t *testing.T) { c := NewChecker(fakeLimits{configured: false}, fakeUsage{usedBytes: 1_000_000_000}) result, err := c.Check(context.Background(), "mandant-a", "postfach-x") if err != nil { t.Fatalf("check: %v", err) } if !result.Allowed { t.Fatalf("erwartete erlaubt ohne konfiguriertes limit, habe: %+v", result) } } func TestCheck_UsageAtOrAboveLimitRejected(t *testing.T) { c := NewChecker(fakeLimits{limitBytes: 1000, configured: true}, fakeUsage{usedBytes: 1000}) result, err := c.Check(context.Background(), "mandant-a", "postfach-x") if err != nil { t.Fatalf("check: %v", err) } if result.Allowed { t.Fatalf("erwartete ablehnung bei verbrauch == limit, habe: %+v", result) } } func TestCheck_UsageBelowLimitAllowed(t *testing.T) { c := NewChecker(fakeLimits{limitBytes: 1000, configured: true}, fakeUsage{usedBytes: 999}) result, err := c.Check(context.Background(), "mandant-a", "postfach-x") if err != nil { t.Fatalf("check: %v", err) } if !result.Allowed { t.Fatalf("erwartete erlaubt bei verbrauch unter limit, habe: %+v", result) } }