Skip to content

Commit

Permalink
ADD func TestParseVmessNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
iotames committed Apr 15, 2024
1 parent 9a85dd0 commit 715c4f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.testFlags": ["-v"]
}
3 changes: 2 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"strconv"
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions parse_nodes_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 715c4f3

Please sign in to comment.