Files
Prism/internal/metrics/breakdown_test.go
T
rose_cat707 fc3a66dc83
CI / docker (push) Has been cancelled
CI / test (push) Has been cancelled
feat: Prism HTTP/SOCKS5 代理网关及管理台
Go 控制面(SQLite + REST API)嵌入 Mihomo 数据面,Vue 3 多语言 Web 管理台。
含订阅/节点/规则/出站/监控/日志、OpenAPI、API Key、Gitea Actions CI(runs-on: ubuntu-latest)
与开源文档;镜像发布至 git.rc707blog.top Container Registry。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 13:41:56 +08:00

47 lines
1.2 KiB
Go

package metrics
import "testing"
func TestAggregateConnections(t *testing.T) {
groups := map[string]bool{
"PROXY": true,
"country_HK": true,
}
conns := []map[string]any{
{
"upload": float64(100),
"download": float64(200),
"metadata": map[string]any{"host": "www.google.com"},
"chains": []any{"PROXY", "node_us_1"},
},
{
"upload": float64(50),
"download": float64(150),
"metadata": map[string]any{"host": "www.google.com"},
"chains": []any{"country_HK", "node_us_1"},
},
{
"upload": float64(10),
"download": float64(20),
"metadata": map[string]any{"host": "api.github.com"},
"chains": []any{"DIRECT"},
},
}
domains, nodes := AggregateConnections(conns, groups)
if len(domains) != 2 {
t.Fatalf("domains: want 2 got %d", len(domains))
}
if domains[0].Label != "www.google.com" || domains[0].NodeKey != "node_us_1" || domains[0].Total != 500 {
t.Fatalf("google row: %+v", domains[0])
}
if domains[1].Label != "api.github.com" || domains[1].NodeKey != "DIRECT" {
t.Fatalf("github row: %+v", domains[1])
}
if len(nodes) != 2 {
t.Fatalf("nodes: want 2 got %d: %+v", len(nodes), nodes)
}
if nodes[0].Key != "node_us_1" {
t.Fatalf("top node: %+v", nodes[0])
}
}