5759c1862e
M0-M7 已完成:核心网关(身份/RBAC/TOTP/OIDC/SAML/Provider/配额/路由/内容策略/审计/定价)+ 资源市场(MCP/Skills/数字员工)。 含 22 个 PostgreSQL 迁移、管理端/门户端前端源码、OpenAPI 契约、部署 compose。 Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package pricing
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCalculateSelectsExactEffectivePrice(t *testing.T) {
|
|
now := time.Date(2026, 8, 11, 0, 0, 0, 0, time.UTC)
|
|
service := &Service{}
|
|
service.current.Store(&priceSnapshot{prices: []Price{
|
|
{ID: "exact", ProviderCode: "openai", ModelPattern: "gpt-5", InputMicrounitsPerMillion: 2_000_000, OutputMicrounitsPerMillion: 8_000_000, Currency: "USD", EffectiveFrom: now.Add(-time.Hour), Enabled: true},
|
|
{ID: "wild", ProviderCode: "openai", ModelPattern: "gpt-*", InputMicrounitsPerMillion: 1, Currency: "USD", EffectiveFrom: now.Add(-time.Hour), Enabled: true},
|
|
}})
|
|
cost := service.Calculate("OPENAI", "gpt-5", 1_000, 500, now)
|
|
if cost.PriceID != "exact" || cost.Microunits != 6_000 {
|
|
t.Fatalf("unexpected cost %#v", cost)
|
|
}
|
|
}
|
|
|
|
func TestCalculateHonorsEffectiveWindow(t *testing.T) {
|
|
now := time.Now().UTC()
|
|
past := now.Add(-time.Hour)
|
|
service := &Service{}
|
|
service.current.Store(&priceSnapshot{prices: []Price{{ID: "expired", ProviderCode: "p1", ModelPattern: "m", InputMicrounitsPerMillion: 1_000_000, Currency: "USD", EffectiveFrom: now.Add(-2 * time.Hour), EffectiveTo: &past, Enabled: true}}})
|
|
if cost := service.Calculate("p1", "m", 100, 0, now); cost.Microunits != 0 {
|
|
t.Fatalf("expired price selected: %#v", cost)
|
|
}
|
|
}
|