mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed? Integrate Go 1.26's new `go fix` into workflow. NOTE that the changes caused our linter to fire; a [separate commit](https://github.com/temporalio/temporal/pull/9337/commits/1b23f787aef370098b35829c4d17dcc06230b4c1) addresses those. ## Why? Ensure Go code is standardized/modernized. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
// Package fakedata provides utilities for generating random data for testing. We recently migrated from gofakeit to
|
|
// go-faker. This was to avoid the problem described here: https://github.com/brianvoe/gofakeit/issues/281#issue-2071796056.
|
|
// To make such migrations easier in the future, and to ensure that we use [faker.SetIgnoreInterface] before any
|
|
// invocation, we created this package.
|
|
package fakedata
|
|
|
|
import (
|
|
"github.com/go-faker/faker/v4"
|
|
)
|
|
|
|
func init() {
|
|
// We need this option to prevent faker.FakeData from returning an error for any struct that has an interface{} field.
|
|
faker.SetIgnoreInterface(true)
|
|
// We need this option to prevent faker from taking a long time while generating random data for structs that have
|
|
// map or slice fields. This is especially relevant for persistence.ShardInfo, which takes about 1s without this
|
|
// option, but only ~100µs with it.
|
|
if err := faker.SetRandomMapAndSliceMaxSize(2); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// FakeStruct generates random data for the given struct pointer. Example usage:
|
|
//
|
|
// var shardInfo persistencespb.ShardInfo
|
|
// _ = fakedata.FakeStruct(&shardInfo)
|
|
func FakeStruct(a any) error {
|
|
return faker.FakeData(a)
|
|
}
|