Files
mrlee 278f8267b7 chore: 初始提交 Fonu 1.0.2
- 公网反代:Nginx 状态卡片(版本 / 运行状态 / 配置校验 / 端口监听)
- 部署设置第一、二梯队(HTTPS 开关、安全头、限流、连接数、仅中国大陆 IP)
- 隧道检测兼容 frps v0.68 / v0.71(V2 与旧版端点)
- 恢复被清空的 internal/frp/store.go、internal/api/ddns_handler.go、web/src/views/DdnsView.vue
2026-09-23 09:40:59 +08:00

54 lines
1.2 KiB
Go

package traffic
import (
"testing"
"time"
"github.com/fonu/fonu/internal/proxy"
)
func TestCollectorAttributesConnectionsByHostAndPort(t *testing.T) {
c := NewCollector(nil, "", nil)
now := time.Now()
line6893 := "2026-09-17T08:30:00+08:00 xxx.com 6893 GET /login 200 0.010 218.88.23.20 192.168.8.3:6893 100 200"
line8443 := "2026-09-17T08:30:01+08:00 xxx.com 8443 GET / 200 0.010 218.88.23.20 192.168.8.3:8443 100 200"
c.ingestLine(line6893, true)
c.ingestLine(line8443, true)
rules := []proxy.Rule{
{
ID: 1,
ListenPort: 6893,
Hosts: []proxy.Host{{Hostname: "xxx.com"}},
},
{
ID: 2,
ListenPort: 8443,
Hosts: []proxy.Host{{Hostname: "xxx.com"}},
},
}
stats := c.SnapshotForRules(rules)
if len(stats) != 2 {
t.Fatalf("expected 2 stats, got %d", len(stats))
}
byID := map[int64]RuleTraffic{}
for _, s := range stats {
byID[s.RuleID] = s
}
if byID[1].Connections != 1 {
t.Fatalf("rule 6893 connections=%d want 1", byID[1].Connections)
}
if byID[2].Connections != 1 {
t.Fatalf("rule 8443 connections=%d want 1", byID[2].Connections)
}
_ = now
}
func TestEndpointKeyIncludesPort(t *testing.T) {
if got := EndpointKey("XXX.com", 6893); got != "xxx.com:6893" {
t.Fatalf("got %q", got)
}
}