2023-02-06 23:03:53 +03:00
|
|
|
package unwrap_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-02-08 14:59:33 +03:00
|
|
|
pb "go.unistack.org/micro-tests/client/grpc/proto"
|
2023-02-06 23:03:53 +03:00
|
|
|
"go.unistack.org/micro/v3/logger/unwrap"
|
2023-02-22 00:12:01 +03:00
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
2023-02-06 23:03:53 +03:00
|
|
|
)
|
|
|
|
|
2023-02-08 14:59:33 +03:00
|
|
|
func TestProtoMessage(t *testing.T) {
|
|
|
|
type Response struct {
|
|
|
|
Val *pb.Response `logger:"take"`
|
|
|
|
}
|
|
|
|
val := &Response{Val: &pb.Response{Msg: "test"}}
|
|
|
|
|
|
|
|
buf := fmt.Sprintf("%#v", unwrap.Unwrap(val, unwrap.Tagged(true)))
|
|
|
|
cmp := `&unwrap_test.Response{Val:(*helloworld.Response){Msg:"test"}}`
|
|
|
|
if strings.Compare(buf, cmp) != 0 {
|
|
|
|
t.Fatalf("not proper written \n%s\n%s", cmp, buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 23:03:53 +03:00
|
|
|
func TestWrappers(t *testing.T) {
|
|
|
|
type CustomerInfo struct {
|
2023-02-22 00:12:01 +03:00
|
|
|
MainPhone *wrapperspb.StringValue `logger:"take"`
|
|
|
|
BankClientId string `logger:"take"`
|
|
|
|
NullString sql.NullString `logger:"take"`
|
2023-02-06 23:03:53 +03:00
|
|
|
}
|
|
|
|
|
2023-02-22 00:12:01 +03:00
|
|
|
c := &CustomerInfo{MainPhone: &wrapperspb.StringValue{Value: "+712334"}, BankClientId: "12345", NullString: sql.NullString{String: "test"}}
|
2023-02-06 23:03:53 +03:00
|
|
|
|
|
|
|
buf := fmt.Sprintf("%#v", unwrap.Unwrap(c, unwrap.Tagged(true)))
|
|
|
|
cmp := `&unwrap_test.CustomerInfo{MainPhone:(*wrapperspb.StringValue){Value:"+712334"}, BankClientId:"12345", NullString:(sql.NullString){String:"test"}}`
|
|
|
|
if strings.Compare(buf, cmp) != 0 {
|
|
|
|
t.Fatalf("not proper written \n%s\n%s", cmp, buf)
|
|
|
|
}
|
|
|
|
}
|