Skip to content

Commit d7db978

Browse files
authored
Merge branch 'master' into testHistoryEventToString
2 parents d34347b + 2801925 commit d7db978

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ $(BIN)/mockery: internal/tools/go.mod
161161
$(call go_build_tool,github.com/vektra/mockery/v2,mockery)
162162

163163
# copyright header checker/writer. only requires stdlib, so no other dependencies are needed.
164-
$(BIN)/copyright: internal/cmd/tools/copyright/licensegen.go
165-
go build -mod=readonly -o $@ ./internal/cmd/tools/copyright/licensegen.go
164+
$(BIN)/copyright: internal/tools/licensegen.go
165+
go build -mod=readonly -o $@ ./internal/tools/licensegen.go
166166

167167
# ensures mod files are in sync for critical packages
168168
$(BUILD)/go_mod_check: go.mod internal/tools/go.mod

internal/common/util/stringer_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,80 @@ import (
3030
"go.uber.org/thriftrw/ptr"
3131
)
3232

33+
func Test_anyToString(t *testing.T) {
34+
testCases := []struct {
35+
name string
36+
thingToSerialize interface{}
37+
expected string
38+
}{
39+
{
40+
name: "nil",
41+
thingToSerialize: nil,
42+
expected: "<nil>",
43+
},
44+
{
45+
name: "int",
46+
thingToSerialize: 1,
47+
expected: "1",
48+
},
49+
{
50+
name: "string",
51+
thingToSerialize: "test",
52+
expected: "test",
53+
},
54+
{
55+
name: "struct",
56+
thingToSerialize: struct {
57+
A string
58+
B int
59+
C bool
60+
}{A: "test", B: 1, C: true},
61+
expected: "(A:test, B:1, C:true)",
62+
},
63+
{
64+
name: "pointer",
65+
thingToSerialize: &struct {
66+
A string
67+
B int
68+
C bool
69+
}{A: "test", B: 1, C: true},
70+
expected: "(A:test, B:1, C:true)",
71+
},
72+
{
73+
name: "slice",
74+
thingToSerialize: []int{1, 2, 3},
75+
expected: "[1 2 3]",
76+
},
77+
{
78+
name: "struct with slice",
79+
thingToSerialize: struct{ A []int }{A: []int{1, 2, 3}},
80+
expected: "(A:[len=3])",
81+
},
82+
{
83+
name: "struct with blob",
84+
thingToSerialize: struct{ A []byte }{A: []byte("blob-data")},
85+
expected: "(A:[blob-data])",
86+
},
87+
{
88+
name: "struct with struct",
89+
thingToSerialize: struct{ A struct{ B int } }{A: struct{ B int }{B: 1}},
90+
expected: "(A:(B:1))",
91+
},
92+
{
93+
name: "struct with pointer",
94+
thingToSerialize: struct{ A *int }{A: new(int)},
95+
expected: "(A:0)",
96+
},
97+
}
98+
99+
for _, tc := range testCases {
100+
t.Run(tc.name, func(t *testing.T) {
101+
actual := anyToString(tc.thingToSerialize)
102+
require.Equal(t, tc.expected, actual)
103+
})
104+
}
105+
}
106+
33107
func Test_byteSliceToString(t *testing.T) {
34108
data := []byte("blob-data")
35109
v := reflect.ValueOf(data)
File renamed without changes.

0 commit comments

Comments
 (0)