로그 변경
peer handler 코드 정리
This commit is contained in:
@ -4,12 +4,9 @@ package wshandler
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/session"
|
||||
)
|
||||
|
||||
type TestReceiver struct {
|
||||
@ -59,52 +56,11 @@ 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) {
|
||||
}
|
||||
|
||||
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) {
|
||||
handler := MakeWebsocketPeerApiHandler[*testpeer]("test")
|
||||
ws := NewWebsocketPeerHandler[*testpeer](&dummySessionConsumer{})
|
||||
ws.AddHandler(handler)
|
||||
|
||||
tp := &testpeer{
|
||||
id: "onlyone",
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
src := []byte(`{"123" :"str1", "456": "str2"}`)
|
||||
var test map[int]string
|
||||
err := json.Unmarshal(src, &test)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user