fusen-render/websocket_test.go
2023-08-03 18:34:20 +08:00

62 lines
1.2 KiB
Go

package fusenrender_test
import (
"fmt"
"fusenrender"
"log"
"net/url"
"testing"
"github.com/gorilla/websocket"
)
func TestWebsocketA(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_a.yaml")
if err != nil {
panic(err)
}
fusenrender.StartNode(svc.ServerID, 128, svc.Address())
fusenrender.HttpStart(svc.Port - 1000)
}
func TestWebsocketB(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_b.yaml")
if err != nil {
panic(err)
}
fusenrender.StartNode(svc.ServerID, 128, svc.Address())
fusenrender.HttpStart(svc.Port - 1000)
}
func TestWebsocketC(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_c.yaml")
if err != nil {
panic(err)
}
fusenrender.StartNode(svc.ServerID, 128, svc.Address())
fusenrender.HttpStart(svc.Port - 1000)
}
var addr = "localhost:4051"
func TestWebsocketCient(t *testing.T) {
u := url.URL{Scheme: "ws", Host: addr, Path: "/ws"}
conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
log.Println(err)
defer conn.Close()
for {
err = conn.WriteMessage(websocket.BinaryMessage, []byte("123"))
if err != nil {
return
}
mt, msg, err := conn.ReadMessage()
fmt.Sprintln(mt, err)
fmt.Printf("Received: %s\n", string(msg))
}
}