mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-14 18:30:02 +08:00
chore: refactor unit tests (#5041)
This commit is contained in:
@@ -177,8 +177,8 @@ func doMarshalJson(v any) ([]byte, error) {
|
|||||||
// why not use json.Marshal? https://github.com/golang/go/issues/28453
|
// why not use json.Marshal? https://github.com/golang/go/issues/28453
|
||||||
// it change the behavior of json.Marshal, like & -> \u0026, < -> \u003c, > -> \u003e
|
// it change the behavior of json.Marshal, like & -> \u0026, < -> \u003c, > -> \u003e
|
||||||
// which is not what we want in logic response
|
// which is not what we want in logic response
|
||||||
buf := &bytes.Buffer{}
|
var buf bytes.Buffer
|
||||||
enc := json.NewEncoder(buf)
|
enc := json.NewEncoder(&buf)
|
||||||
enc.SetEscapeHTML(false)
|
enc.SetEscapeHTML(false)
|
||||||
if err := enc.Encode(v); err != nil {
|
if err := enc.Encode(v); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type message struct {
|
type message struct {
|
||||||
@@ -449,6 +448,7 @@ func Test_doMarshalJson(t *testing.T) {
|
|||||||
type args struct {
|
type args struct {
|
||||||
v any
|
v any
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
@@ -532,15 +532,16 @@ func Test_doMarshalJson(t *testing.T) {
|
|||||||
wantErr: assert.NoError,
|
wantErr: assert.NoError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(
|
tt := tt
|
||||||
tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := doMarshalJson(tt.args.v)
|
got, err := doMarshalJson(tt.args.v)
|
||||||
if !tt.wantErr(t, err, fmt.Sprintf("doMarshalJson(%v)", tt.args.v)) {
|
if !tt.wantErr(t, err, fmt.Sprintf("doMarshalJson(%v)", tt.args.v)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.Equalf(t, string(tt.want), string(got), "doMarshalJson(%v)", tt.args.v)
|
|
||||||
},
|
assert.Equalf(t, string(tt.want), string(got), "doMarshalJson(%v)", tt.args.v)
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user