peer 코드 정리

This commit is contained in:
2023-12-23 15:35:10 +09:00
parent c281bf1cfa
commit 02512a48cf
2 changed files with 14 additions and 65 deletions

View File

@ -4,13 +4,9 @@ package wshandler
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"reflect"
"testing"
"github.com/gorilla/websocket"
"repositories.action2quare.com/ayo/gocommon/session"
)
type TestReceiver struct {
@ -60,57 +56,6 @@ func TestUnmarshalToken(t *testing.T) {
// con.AddHandler(receiver)
}
type testpeer struct {
id string
}
func (ph *testpeer) ApiFunc1(arg1 string, arg2 int) error {
fmt.Println("ApiFunc1", ph.id, arg1, arg2)
return errors.New("fake")
}
func (ph *testpeer) ApiFunc2(arg1 string, arg2 map[string]int) (string, error) {
fmt.Println("ApiFunc2", ph.id, arg1, arg2)
return "success", nil
}
func (ph *testpeer) ApiFunc3(arg1 float64, arg2 []int) {
fmt.Println("ApiFunc3", ph.id, arg1, arg2)
}
func (ph *testpeer) ClientDisconnected(reason string) {
}
func (ph *testpeer) ClientConnected(*websocket.Conn) {
}
type dummySessionConsumer struct {
}
func (dsc *dummySessionConsumer) Query(string) (session.Authorization, error) {
return session.Authorization{}, nil
}
func (dsc *dummySessionConsumer) Touch(string) (session.Authorization, error) {
return session.Authorization{}, nil
}
func TestPeerApiBroker(t *testing.T) {
ws := NewWebsocketPeerHandler[*testpeer](&dummySessionConsumer{}, "test")
tp := &testpeer{
id: "onlyone",
}
func1args, _ := json.Marshal([]any{string("arg1"), int(100)})
ws.Call(tp, "test.ApiFunc1", bytes.NewBuffer(func1args))
func1args, _ = json.Marshal([]any{string("arg1"), map[string]int{"arg2.key": 99}})
ws.Call(tp, "test.ApiFunc2", bytes.NewBuffer(func1args))
func1args, _ = json.Marshal([]any{float64(111.1), []int{99, 98}})
ws.Call(tp, "test.ApiFunc3", bytes.NewBuffer(func1args))
}
func TestUnmarshal(t *testing.T) {
src := []byte(`{"123" :"str1", "456": "str2"}`)
var test map[int]string