From 715c4f320d7270a740afdeebd72acebb966569db Mon Sep 17 00:00:00 2001 From: wuhanqing <554553400@qq.com> Date: Mon, 15 Apr 2024 17:58:31 +0800 Subject: [PATCH] ADD func TestParseVmessNodes --- .vscode/settings.json | 3 +++ client/main.go | 3 ++- parse_nodes_test.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 parse_nodes_test.go diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..35a780a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "go.testFlags": ["-v"] +} \ No newline at end of file diff --git a/client/main.go b/client/main.go index 789b706..d24ec23 100644 --- a/client/main.go +++ b/client/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "flag" "fmt" "strconv" @@ -84,7 +85,7 @@ func main() { nd := vp.V2rayNode{ Protocol: "vmess", Add: addr, - Port: port, + Port: json.Number(port), Net: nett, Id: id, Tls: tls, diff --git a/parse_nodes_test.go b/parse_nodes_test.go new file mode 100644 index 0000000..2e821b4 --- /dev/null +++ b/parse_nodes_test.go @@ -0,0 +1,36 @@ +package v2raypool + +import ( + "encoding/base64" + "fmt" + "strings" + "testing" +) + +// func TestInitSubscribeData(t *testing.T) {} +type TestSubscribeData1 struct { + Protocol, Data string +} + +func TestParseVmessNodes(t *testing.T) { + rawnds := []string{ + `{"add":"jp6.xxx.top","host":"","id":"0999AE93-1330-4A75-DBC1-0DD5XXXXXXXX","net":"ws","path":"","port":"4147","ps":"xxx-v2-JP-Tokyo6","tls":"","v":2,"aid":0,"type":"none"}`, + `{"add":"hk6.xxx.top","host":"","id":"93EA57CE-EA21-7240-EE7F-317FXXXXXXXX","net":"ws","path":"","port":4446,"ps":"xxx-v2-HK-HongKong6","tls":"tls","v":2,"aid":0,"type":"none"}`, + `{"add":"jp6.xxx.top","host":"","id":"0999AE93-1330-4A75-DBC1-0DD5XXXXXXXX","net":"ws","path":"","port":"4145","ps":"xxx-v2-JP-Tokyo6","tls":"","v":"2","aid":"0","type":"none"}`, + } + + for i, row := range rawnds { + rawnds[i] = fmt.Sprintf(`vmess://%s`, base64.StdEncoding.EncodeToString([]byte(row))) + } + rawdata := base64.StdEncoding.EncodeToString([]byte(strings.Join(rawnds, "\n"))) + dt, err := parseSubscribeByRaw(rawdata) + if err != nil { + t.Error(err) + } + t.Logf("-----dt(%s)-----\n", dt) + nds := ParseV2rayNodes(dt) + if len(nds) != len(rawnds) { + t.Error("ParseV2rayNodes err") + } + t.Logf("---(%+v)---", nds) +}