github.com/laof/lite-speed-test@v0.0.0-20230930011949-1f39b7037845/web/render/table_test.go (about) 1 package render 2 3 import ( 4 "fmt" 5 "math/rand" 6 "path/filepath" 7 "testing" 8 ) 9 10 func TestDefaultTable(t *testing.T) { 11 nodes := make([]Node, 50) 12 for i := 0; i < 50; i++ { 13 nodes[i] = Node{ 14 Group: "节点列表", 15 Remarks: fmt.Sprintf("美国加利福尼亚免费测试%d", i), 16 Protocol: "vmess", 17 Ping: fmt.Sprintf("%d", rand.Intn(800-50)+50), 18 AvgSpeed: int64((rand.Intn(20-1) + 1) * 1024 * 1024), 19 MaxSpeed: int64((rand.Intn(60-5) + 5) * 1024 * 1024), 20 } 21 } 22 fontPath, _ := filepath.Abs("../misc/WenQuanYiMicroHei-01.ttf") 23 table, err := DefaultTable(nodes, fontPath) 24 if err != nil { 25 t.Error(err) 26 } 27 msg := table.FormatTraffic("10.2G", "3m13s", "50/50") 28 table.Draw("out.png", msg) 29 } 30 31 func TestCSV2Nodes(t *testing.T) { 32 nodes, err := CSV2Nodes("/home/arch/Downloads/test.csv") 33 if err != nil { 34 t.Error(err) 35 } 36 fmt.Println(nodes) 37 } 38 39 func TestGetNodeHeaders(t *testing.T) { 40 _, tags := getNodeHeaders("en") 41 for k, v := range tags { 42 fmt.Printf("%s:%s\n", k, v) 43 } 44 }