go-faker / faker

Go (Golang) Fake Data Generator for Struct, previously https://github.com/bxcodec/faker
https://pkg.go.dev/github.com/go-faker/faker/v4
MIT License
614 stars 30 forks source link

tests and fix for faking data for slice of structs with slice_len specified #19

Closed cwinters8 closed 5 months ago

cwinters8 commented 1 year ago

I was seeing Unknown Type errors when attempting to fake data for a slice of structs or slice of pointers to structs with the slice_len tag specified, which can be reproduced by running something similar to either of the added tests from this PR without the implemented fix in place. The fix here allows for generating fake data in these scenarios.

Open to any feedback you may have. I apologize for the linter making changes to some of the comments here. The Go linter in VS Code is opinionated 🤦‍♂️

bxcodec commented 9 months ago

Hi @cwinters8 , new update pushed to Master, can you help to pull the latest update and resolve the conflict, please?

cwinters8 commented 5 months ago

Hey @bxcodec I'm sorry for not getting to this for so long. I'm pulling this down again to resolve the conflict. New commit headed this way shortly.

cwinters8 commented 5 months ago

@bxcodec should be set! Let me know if there's anything else.

cwinters8 commented 5 months ago

I think the test check failed because TestGetRealAddress ended up randomly getting this address back from Address.realWorld, which gets a random address ultimately from the data stored in misc/addresses-us-1000.min.json:

{
  "address1": "3 Southerberry Drive",
  "address2": "",
  "state": "VT",
  "postalCode": "05468",
  "coordinates": { "lat": 44.62322460000001, "lng": -73.1326629 }
}

As you can see, that address doesn't have a city, and the test checks if the city is empty. When I run the tests locally using the same flags in the workflow step that failed, it doesn't fail, presumably because its grabbing some other address instead.

I just pushed a commit to fix the problem in the json file.

bxcodec commented 5 months ago

Thanks @cwinters8 , merged