feat: add Go backend
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"hotgo/internal/model/entity"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
func TestAggregateDashboardMetric(t *testing.T) {
|
||||
rows := []*entity.DashboardDailyStat{
|
||||
{StatDate: gtime.New("2026-10-01"), DimensionType: dashboardDimensionGlobal, MetricCode: "trade_order", MetricCount: 2, MetricAmount: 1200},
|
||||
{StatDate: gtime.New("2026-10-02"), DimensionType: dashboardDimensionGlobal, MetricCode: "trade_order", MetricCount: 3, MetricAmount: 2300},
|
||||
{StatDate: gtime.New("2026-10-01"), DimensionType: dashboardDimensionGlobal, MetricCode: "member_total", MetricCount: 10},
|
||||
{StatDate: gtime.New("2026-10-02"), DimensionType: dashboardDimensionGlobal, MetricCode: "member_total", MetricCount: 12},
|
||||
}
|
||||
|
||||
orderCount := aggregateDashboardMetric(rows, dashboardMetricDefinition{Code: "trade_order", ValueType: "count", Aggregation: "sum"})
|
||||
if orderCount != 5 {
|
||||
t.Fatalf("order count = %d, want 5", orderCount)
|
||||
}
|
||||
orderAmount := aggregateDashboardMetric(rows, dashboardMetricDefinition{Code: "trade_order", ValueType: "amount", Aggregation: "sum"})
|
||||
if orderAmount != 3500 {
|
||||
t.Fatalf("order amount = %d, want 3500", orderAmount)
|
||||
}
|
||||
memberTotal := aggregateDashboardMetric(rows, dashboardMetricDefinition{Code: "member_total", ValueType: "count", Aggregation: "latest"})
|
||||
if memberTotal != 12 {
|
||||
t.Fatalf("member total = %d, want 12", memberTotal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardChangeRate(t *testing.T) {
|
||||
if value := dashboardChangeRate(120, 100); value != 20 {
|
||||
t.Fatalf("change rate = %v, want 20", value)
|
||||
}
|
||||
if value := dashboardChangeRate(0, 0); value != 0 {
|
||||
t.Fatalf("zero change rate = %v, want 0", value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user