Files
oci-portal/internal/oci/account_test.go
T

39 lines
1.8 KiB
Go

package oci
import (
"testing"
"oci-portal/internal/model"
)
func TestClassifyAccount(t *testing.T) {
tests := []struct {
name string
paymentModel string
tier string
promotionStatus string
want string
}{
{name: "按量付费为付费账户", paymentModel: "Pay as you go", want: model.AccountTypePaid},
{name: "月度账单为付费账户", paymentModel: "Monthly", want: model.AccountTypePaid},
{name: "试用中促销激活", paymentModel: "FREE_TRIAL", promotionStatus: "ACTIVE", want: model.AccountTypeTrial},
{name: "试用中按层级判定", paymentModel: "FREE_TRIAL", tier: "FREE_AND_TRIAL", want: model.AccountTypeTrial},
{name: "促销过期为免费账户", paymentModel: "FREE_TRIAL", promotionStatus: "EXPIRED", want: model.AccountTypeFree},
{name: "免费层级为免费账户", paymentModel: "FREE_TRIAL", tier: "FREE", want: model.AccountTypeFree},
{name: "促销激活优先于免费层级", paymentModel: "FREE_TRIAL", tier: "FREE", promotionStatus: "ACTIVE", want: model.AccountTypeTrial},
{name: "试用但无促销无层级", paymentModel: "FREE_TRIAL", want: model.AccountTypeUnknown},
{name: "全部为空无法判定", want: model.AccountTypeUnknown},
{name: "大小写不敏感", paymentModel: "free_trial", promotionStatus: "active", want: model.AccountTypeTrial},
{name: "促销初始化状态不判定", paymentModel: "FREE_TRIAL", promotionStatus: "INITIALIZED", want: model.AccountTypeUnknown},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ClassifyAccount(tt.paymentModel, tt.tier, tt.promotionStatus)
if got != tt.want {
t.Errorf("ClassifyAccount(%q, %q, %q) = %q, want %q",
tt.paymentModel, tt.tier, tt.promotionStatus, got, tt.want)
}
})
}
}