mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
Fix compile errors on macOS and add some tests
This commit is contained in:
27
tests/cmd_test.go
Normal file
27
tests/cmd_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCmd(t *testing.T) {
|
||||
t.Log("TestCmd")
|
||||
pbm := cmd.NewCmdProtoMap()
|
||||
ping_req1 := pbm.GetProtoObjByCmdId(cmd.PingReq)
|
||||
t1 := reflect.TypeOf(ping_req1)
|
||||
t.Log(t1, t1.Elem(), t1.Elem().Name())
|
||||
ping_req2 := new(proto.PingReq)
|
||||
t2 := reflect.TypeOf(ping_req2)
|
||||
t.Log(t2, t2.Elem(), t2.Elem().Name())
|
||||
assert.Equal(t, t1.Elem().Name(), t2.Elem().Name())
|
||||
assert.Equal(t, pbm.GetCmdNameByCmdId(cmd.PingReq), "PingReq")
|
||||
assert.Equal(t, int(pbm.GetCmdIdByCmdName("PingReq")), cmd.PingReq)
|
||||
assert.Equal(t, int(pbm.GetCmdIdByProtoObj(ping_req1)), cmd.PingReq)
|
||||
assert.Equal(t, int(pbm.GetCmdIdByProtoObj(ping_req2)), cmd.PingReq)
|
||||
}
|
||||
19
tests/logger_test.go
Normal file
19
tests/logger_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
config.CONF = &config.Config{Logger: config.Logger{Level: "DEBUG", Mode: "CONSOLE", Track: true}}
|
||||
|
||||
logger.InitLogger("logger_test")
|
||||
defer logger.CloseLogger()
|
||||
logger.Warn("logger test ...")
|
||||
for i := 0; i < 100; i++ {
|
||||
go func(x int) { logger.Info("%d", x) }(i)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user