You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB
Go

package grpcall
import (
"testing"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/protobuf/types/known/emptypb"
)
func TestJsonpbUnmarshalString(t *testing.T) {
msg := &wrappers.Int64Value{}
if err := jsonpb.UnmarshalString(`123`, msg); err != nil {
t.Error(err)
}
t.Log(msg)
}
func TestJsonpbMarshalString(t *testing.T) {
msg := &wrappers.Int64Value{Value: 123}
marshaler := &jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(msg); err != nil {
t.Error(err)
} else {
t.Log(json) // "123"
}
}
func TestJsonpbMarshalEmpty(t *testing.T) {
msg := &emptypb.Empty{}
marshaler := &jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(msg); err != nil {
t.Error(err)
} else {
t.Log(json) // {}
}
}
// func TestNewJsonRequestParser(t *testing.T) {
// var str_msg wrapperspb.StringValue
// inData := `"abc"`
// if err := NewJsonRequestParser(nil, inData).Next(&str_msg); err != nil {
// t.Error(err)
// }
// t.Log("string", str_msg.GetValue())
// var int_msg wrapperspb.Int64Value
// inData = `"10"` // or `10`
// if err := NewJsonRequestParser(nil, inData).Next(&int_msg); err != nil {
// t.Error(err)
// }
// t.Log("int", int_msg.GetValue())
// }