File tree Expand file tree Collapse file tree 2 files changed +63
-1
lines changed
Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ type faker struct {
1818
1919var errEFaceNotAllowed = errors .New ("any not allowed" )
2020
21- func (f faker ) getFakedValue (a any ) (reflect.Value , error ) {
21+ func (f * faker ) getFakedValue (a any ) (reflect.Value , error ) {
2222 t := reflect .TypeOf (a )
2323 if t == nil {
2424 return reflect.Value {}, errEFaceNotAllowed
Original file line number Diff line number Diff line change 66 "testing"
77 "time"
88
9+ "github.com/rs/zerolog"
910 "github.com/stretchr/testify/assert"
11+ "github.com/stretchr/testify/require"
1012)
1113
1214type testFakerStruct struct {
@@ -97,3 +99,63 @@ func TestFakerCanFakeNetIP(t *testing.T) {
9799 assert .NotEmpty (t , a .NestedComplex .IPAddress )
98100 assert .Equal (t , "1.1.1.1" , a .NestedComplex .IPAddress .String ())
99101}
102+
103+ func TestMaxDepth (t * testing.T ) {
104+ // Struct with nested structs
105+ a := struct {
106+ A struct {
107+ A struct {
108+ A struct {
109+ A struct {
110+ A struct {
111+ A struct {
112+ A struct {
113+ A struct {
114+ A struct {
115+ A struct {
116+ A struct {
117+ A struct {
118+ A struct {
119+ A struct {
120+ A struct {
121+ A struct {
122+ A struct {
123+ A string
124+ }
125+ }
126+ }
127+ }
128+ }
129+ }
130+ }
131+ }
132+ }
133+ }
134+ }
135+ }
136+ }
137+ }
138+ }
139+ }
140+ }
141+ }{}
142+
143+ sink := & testLogSink {}
144+ testLogger := zerolog .New (sink )
145+ require .NoError (t , FakeObject (& a , WithLogger (testLogger )), "max depth reached" )
146+ require .Equal (t , 1 , len (sink .getLogs ()))
147+ require .Contains (t , sink .getLogs ()[0 ], "max_depth reached" )
148+ }
149+
150+ type testLogSink struct {
151+ logs []string
152+ }
153+
154+ func (sink * testLogSink ) Write (p []byte ) (n int , err error ) {
155+ sink .logs = append (sink .logs , string (p ))
156+ return len (p ), nil
157+ }
158+
159+ func (sink * testLogSink ) getLogs () []string {
160+ return sink .logs
161+ }
You can’t perform that action at this time.
0 commit comments