production runtime and mock removal
This commit is contained in:
1 parent
2ef3da7af5
commit
6480e503eb
55 files changed
+581
-540
No files matched your search
@@ -12,9 +12,10 @@ import (
|
||||
const CurrencyCNY = "CNY"
|
||||
|
||||
var (
|
||||
ErrAmbiguousPriceRule = errors.New("billing price rules are ambiguous")
|
||||
ErrPriceRuleNotFound = errors.New("billing price rule not found")
|
||||
ErrParameterTier = errors.New("billing parameter tier not found")
|
||||
ErrAmbiguousPriceRule = errors.New("billing price rules are ambiguous")
|
||||
ErrPriceRuleNotFound = errors.New("billing price rule not found")
|
||||
ErrParameterTier = errors.New("billing parameter tier not found")
|
||||
ErrProviderUnavailable = errors.New("billing provider is unavailable")
|
||||
)
|
||||
|
||||
type Unit string
|
||||
@@ -103,9 +104,12 @@ type Quote struct {
|
||||
type Catalog struct{ Rules []PriceRule }
|
||||
|
||||
func (c Catalog) Quote(input QuoteInput) (*Quote, error) {
|
||||
if input.BillingDisabled || input.Provider == "mock" {
|
||||
if input.BillingDisabled {
|
||||
return nil, nil
|
||||
}
|
||||
if input.Provider == "mock" {
|
||||
return nil, ErrProviderUnavailable
|
||||
}
|
||||
type candidate struct {
|
||||
rule PriceRule
|
||||
req, conditions, priority int
|
||||
|
||||
@@ -60,18 +60,17 @@ func TestCatalogRejectsAmbiguousWinners(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogExemptsDisabledMockAndSuperAdmin(t *testing.T) {
|
||||
func TestCatalogExemptsDisabledBillingAndRejectsRemovedMockProvider(t *testing.T) {
|
||||
rule := PriceRule{ID: "r", Provider: "bailian", Capability: "image.generate", Unit: UnitRequest, StandardUnitPriceFen: 10, MarkupMultiplier: 1, Enabled: true}
|
||||
for _, input := range []QuoteInput{
|
||||
{BillingDisabled: true, Provider: "bailian", Capability: "image.generate"},
|
||||
{Provider: "mock", Capability: "image.generate"},
|
||||
} {
|
||||
quote, err := (Catalog{Rules: []PriceRule{rule}}).Quote(input)
|
||||
if err != nil || quote != nil {
|
||||
t.Fatalf("Quote(%#v) = %#v, %v", input, quote, err)
|
||||
}
|
||||
quote, err := (Catalog{Rules: []PriceRule{rule}}).Quote(QuoteInput{BillingDisabled: true, Provider: "bailian", Capability: "image.generate"})
|
||||
if err != nil || quote != nil {
|
||||
t.Fatalf("disabled Quote = %#v, %v", quote, err)
|
||||
}
|
||||
quote, err := (Catalog{Rules: []PriceRule{rule}}).Quote(QuoteInput{Provider: "bailian", Capability: "image.generate", Source: "platform", Role: "super_admin"})
|
||||
quote, err = (Catalog{Rules: []PriceRule{rule}}).Quote(QuoteInput{Provider: "mock", Capability: "image.generate"})
|
||||
if quote != nil || !errors.Is(err, ErrProviderUnavailable) {
|
||||
t.Fatalf("removed provider Quote = %#v, %v", quote, err)
|
||||
}
|
||||
quote, err = (Catalog{Rules: []PriceRule{rule}}).Quote(QuoteInput{Provider: "bailian", Capability: "image.generate", Source: "platform", Role: "super_admin"})
|
||||
if err != nil || quote == nil || !quote.QuotaExempt {
|
||||
t.Fatalf("quote = %#v, %v", quote, err)
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ func HTTPStatus(err error) int {
|
||||
if errors.As(err, &status) {
|
||||
return status.Status
|
||||
}
|
||||
if errors.Is(err, ErrProviderUnavailable) {
|
||||
return 503
|
||||
}
|
||||
return 500
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user