protojson

This commit is contained in:
withchao 2024-04-16 15:02:54 +08:00
parent ef3081b4b7
commit bc39e465ca

View File

@ -15,7 +15,12 @@
package cmd package cmd
import ( import (
"github.com/openimsdk/protocol/auth"
"github.com/openimsdk/tools/apiresp"
"github.com/openimsdk/tools/utils/jsonutil"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"math"
"testing"
) )
// MockRootCmd is a mock type for the RootCmd type // MockRootCmd is a mock type for the RootCmd type
@ -27,3 +32,30 @@ func (m *MockRootCmd) Execute() error {
args := m.Called() args := m.Called()
return args.Error(0) return args.Error(0)
} }
func TestName(t *testing.T) {
resp := &apiresp.ApiResponse{
ErrCode: 1234,
ErrMsg: "test",
ErrDlt: "4567",
Data: &auth.UserTokenResp{
Token: "1234567",
ExpireTimeSeconds: math.MaxInt64,
},
}
data, err := resp.MarshalJSON()
if err != nil {
panic(err)
}
t.Log(string(data))
var rReso apiresp.ApiResponse
rReso.Data = &auth.UserTokenResp{}
if err := jsonutil.JsonUnmarshal(data, &rReso); err != nil {
panic(err)
}
t.Logf("%+v\n", rReso)
}