faker
faker copied to clipboard
feat: FakeData support recursive type
original FakeData()
will cause stack overflow when it handling recursive type:
type BinaryTreeNode struct {
Val int
Left *BinaryTreeNode
Right *BinaryTreeNode
}
func TestFakeData_RecursiveType(t *testing.T) {
toJSON := func(val interface{}) string {
data, _ := json.MarshalIndent(val, "", " ")
return string(data)
}
node1 := BinaryTreeNode{}
if err := FakeData(&node1); err != nil {
t.Errorf("%+v", err)
t.FailNow()
}
t.Log("binary tree node:", toJSON(node1))
}
runtime: goroutine stack exceeds 1000000000-byte limit
...
fatal error: stack overflow
Hi @wolf-joe
Can we utilize this proposal #160? I'm thinking to re-use the capability to support this -- re: options
Let me know if it's possible, so I can merge that PR cc @unkeep to assist
Hi @wolf-joe
Can we utilize this proposal #160? I'm thinking to re-use the capability to support this -- re: options
Let me know if it's possible, so I can merge that PR cc @unkeep to assist
you mean we can set recursionMaxDepth
by option?
Actually, this is a critical, can not be an option
But I'm curious if it's possible to set the recursionMaxDepth
by using option?
custom recursionMaxDepth
is attractive idea for me, const value cannot handle every case. I will try another version base #160 this weekend, you can merge #160 if you want.
closing this because of this #168