fix(billing): improve quota handling and error reporting for pre-consume operations

This commit is contained in:
CaIon
2026-07-11 13:14:22 +08:00
parent 621927f710
commit d9595831bf
12 changed files with 246 additions and 61 deletions
+18
View File
@@ -6,6 +6,7 @@ import (
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// 2000 quota per call * n=18446744073686646784 overflows int64; the constant
@@ -78,6 +79,23 @@ func TestQuotaFromFloatChecked(t *testing.T) {
}
}
func TestQuotaFromFloatStrictReturnsTypedClampError(t *testing.T) {
quota, err := QuotaFromFloatStrict(42.9)
require.NoError(t, err)
assert.Equal(t, 42, quota)
quota, err = QuotaFromFloatStrict(overflowingProduct)
assert.Zero(t, quota)
var clamp *QuotaClamp
require.ErrorAs(t, err, &clamp)
assert.Equal(t, QuotaClampOverflow, clamp.Kind)
assert.Equal(t, MaxQuota, clamp.Clamped)
assert.ErrorContains(t, err, "QuotaFromFloat")
assert.ErrorContains(t, err, "overflow")
assert.ErrorContains(t, err, "original=")
assert.ErrorContains(t, err, "clamped=2147483647")
}
// TestQuotaRoundChecked verifies the rounding entry point reports clamps the
// same way.
func TestQuotaRoundChecked(t *testing.T) {