MCPcopy Index your code
hub / github.com/coder/coder / Fake

Function Fake

testutil/faker.go:18–27  ·  view source on GitHub ↗

Fake will populate any zero fields in the provided struct with fake data. Non-zero fields will remain unchanged. Usage: key := Fake(t, faker, database.APIKey{ TokenName: "keep-my-name", })

(t *testing.T, faker *gofakeit.Faker, seed T)

Source from the content-addressed store, hash-verified

16// TokenName: "keep-my-name",
17// })
18func Fake[T any](t *testing.T, faker *gofakeit.Faker, seed T) T {
19 t.Helper()
20
21 var tmp T
22 err := faker.Struct(&tmp)
23 require.NoError(t, err, "failed to generate fake data for type %T", tmp)
24
25 mergeZero(&seed, tmp)
26 return seed
27}
28
29// mergeZero merges the fields of src into dst, but only if the field in dst is
30// currently the zero value.

Callers 15

TestInTXFunction · 0.92
TestNewFunction · 0.92
TestAPIKeyMethod · 0.92
TestChatsMethod · 0.92
TestFileMethod · 0.92
TestGroupMethod · 0.92
TestProvisionerJobMethod · 0.92
TestOrganizationMethod · 0.92
TestWorkspaceProxyMethod · 0.92
TestTemplateMethod · 0.92
TestUserMethod · 0.92

Calls 2

mergeZeroFunction · 0.85
HelperMethod · 0.65

Tested by 15

TestInTXFunction · 0.74
TestNewFunction · 0.74
TestAPIKeyMethod · 0.74
TestChatsMethod · 0.74
TestFileMethod · 0.74
TestGroupMethod · 0.74
TestProvisionerJobMethod · 0.74
TestOrganizationMethod · 0.74
TestWorkspaceProxyMethod · 0.74
TestTemplateMethod · 0.74
TestUserMethod · 0.74