Build way-node / Test, Build, Push (push) Failing after 14s
- Go module: github.com/cedar2025/xboard-node → github.com/viaeon/way-node(307 处 import 同步) - cmd/xboard-node/ → cmd/way-node/ - install.sh: APP_NAME / INSTALL_ROOT(/etc/way-node) / BINARY_PATH / SERVICE_NAME 全部更名, 下载源与 Documentaion 指向 git.viaeon.com/admin/way-node - Makefile / Dockerfile 产物与镜像路径更名 - README 全篇重写链接 - 新增 .gitea/workflows/build.yml:容器内跑测试 + 交叉编译 + 构建镜像推 git.viaeon.com/admin/way-node 构建全程在 golang:1.26 容器里,不依赖 runner 宿主装 Go - 禁用 .github/workflows/ci.yml(依赖 ghcr.io 与 GITHUB_TOKEN,Gitea 上跑不通) 保留:xbctl 工具名(不含旧品牌)、go.sum 里上游依赖哈希
85 lines
3.0 KiB
Go
85 lines
3.0 KiB
Go
package model
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/viaeon/way-node/internal/config"
|
|
"github.com/viaeon/way-node/internal/panel"
|
|
)
|
|
|
|
func TestNodeSpecFromPanelValidated(t *testing.T) {
|
|
t.Run("valid custom outbounds and route targets", func(t *testing.T) {
|
|
node, err := NodeSpecFromPanelValidated(&panel.NodeConfig{
|
|
Protocol: "shadowsocks",
|
|
ServerPort: 8388,
|
|
CustomOutbounds: []panel.OutboundConfig{
|
|
{Tag: "warp", Protocol: "wireguard", Settings: map[string]any{"server": "1.1.1.1", "server_port": 2408, "private_key": "pk"}},
|
|
{Tag: "proxy", Protocol: "socks", ProxyTag: "warp", Settings: map[string]any{"server": "2.2.2.2", "server_port": 1080}},
|
|
},
|
|
CustomRouteRules: []panel.CustomRouteRule{{
|
|
Action: panel.RouteAction{Type: "route", Target: "proxy"},
|
|
Match: panel.RouteMatch{DomainSuffixes: []string{"example.com"}},
|
|
}},
|
|
}, config.KernelConfig{Type: "singbox"})
|
|
if err != nil {
|
|
t.Fatalf("NodeSpecFromPanelValidated: %v", err)
|
|
}
|
|
if node == nil || len(node.CustomOutbounds) != 2 {
|
|
t.Fatalf("unexpected node spec: %#v", node)
|
|
}
|
|
})
|
|
|
|
t.Run("invalid custom outbounds", func(t *testing.T) {
|
|
_, err := NodeSpecFromPanelValidated(&panel.NodeConfig{
|
|
Protocol: "shadowsocks",
|
|
ServerPort: 8388,
|
|
CustomOutbounds: []panel.OutboundConfig{{
|
|
Tag: "proxy", Protocol: "socks", ProxyTag: "missing", Settings: map[string]any{"server": "2.2.2.2", "server_port": 1080},
|
|
}},
|
|
}, config.KernelConfig{Type: "singbox"})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `custom_outbounds[0].proxy_tag references unknown outbound "missing"`) {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("reject unsupported protocol for kernel", func(t *testing.T) {
|
|
_, err := NodeSpecFromPanelValidated(&panel.NodeConfig{
|
|
Protocol: "shadowsocks",
|
|
ServerPort: 8388,
|
|
CustomOutbounds: []panel.OutboundConfig{{
|
|
Tag: "hy2", Protocol: "hysteria2", Settings: map[string]any{"server": "2.2.2.2", "server_port": 8443},
|
|
}},
|
|
}, config.KernelConfig{Type: "xray"})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `protocol "hysteria2" is not supported by kernel "xray"`) {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("reject unknown route target", func(t *testing.T) {
|
|
_, err := NodeSpecFromPanelValidated(&panel.NodeConfig{
|
|
Protocol: "shadowsocks",
|
|
ServerPort: 8388,
|
|
CustomOutbounds: []panel.OutboundConfig{{
|
|
Tag: "warp", Protocol: "wireguard", Settings: map[string]any{"server": "1.1.1.1", "server_port": 2408, "private_key": "pk"},
|
|
}},
|
|
CustomRouteRules: []panel.CustomRouteRule{{
|
|
Action: panel.RouteAction{Type: "route", Target: "missing"},
|
|
Match: panel.RouteMatch{DomainSuffixes: []string{"example.com"}},
|
|
}},
|
|
}, config.KernelConfig{Type: "singbox"})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), `custom_route_rules[0].action.target references unknown outbound "missing"`) {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
})
|
|
}
|