Skip to content

Commit f44e875

Browse files
committed
补充 struct 传参时 time 类型的单元测试。
1 parent ef58ac3 commit f44e875

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

abstract_db_client_test.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ import (
66
"time"
77
)
88

9-
type StrA struct {
10-
A string
11-
}
12-
13-
type StrB struct {
14-
B string
15-
}
16-
17-
type StrAB struct {
18-
A string
19-
B string
20-
}
21-
22-
type StrABC struct {
23-
StrAB
24-
C string
25-
}
26-
279
func Test_preHandleArgs(t *testing.T) {
2810
type TypeA struct {
2911
A string
@@ -43,6 +25,11 @@ func Test_preHandleArgs(t *testing.T) {
4325
C string
4426
}
4527

28+
type TypeTimeA struct {
29+
TypeA
30+
Time time.Time
31+
}
32+
4633
testTime := time.Date(2021, 7, 3, 0, 0, 0, 0, time.UTC)
4734

4835
t.Run("empty_args", func(t *testing.T) {
@@ -155,6 +142,22 @@ func Test_preHandleArgs(t *testing.T) {
155142
}
156143
})
157144

145+
t.Run("time_convert", func(t *testing.T) {
146+
testTime := time.Now()
147+
paramTimeA := TypeTimeA{
148+
TypeA: TypeA{A: "abc_a"},
149+
Time: testTime,
150+
}
151+
got, err := preHandleArgs(paramTimeA)
152+
if err != nil {
153+
t.Errorf("mergeArgs() error = %v, wantErr false", err)
154+
return
155+
}
156+
if !reflect.DeepEqual(got, []any{map[string]any{"A": "abc_a", "Time": testTime}}) {
157+
t.Errorf("mergeArgs() = %v, want %v", got, []any{map[string]any{"A": "abc_a", "Time": testTime}})
158+
}
159+
})
160+
158161
t.Run("mixed_types", func(t *testing.T) {
159162
args := []any{
160163
TypeAB{TypeA: TypeA{A: "ab_a"}, TypeB: TypeB{B: "ab_b"}},

0 commit comments

Comments
 (0)