Skip to content

Commit 5ba3463

Browse files
committed
Remove use of panics
1 parent 7fc8ead commit 5ba3463

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

coderd/database/databasefake/generator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type Generator struct {
3131

3232
func NewGenerator(t *testing.T, db database.Store) *Generator {
3333
if _, ok := db.(FakeDatabase); !ok {
34-
panic("Generator db must be a FakeDatabase")
34+
// This does not work for postgres databases because of foreign key
35+
// constraints
36+
t.Fatalf("Generator db must be a FakeDatabase")
3537
}
3638
return &Generator{
3739
names: make(map[string]uuid.UUID),
@@ -58,6 +60,7 @@ func (g *Generator) PrimaryOrg(ctx context.Context) database.Organization {
5860
}
5961

6062
func populate[DBType any](ctx context.Context, g *Generator, name string, seed DBType) DBType {
63+
g.testT.Helper()
6164
if name == "" {
6265
name = g.RandomName()
6366
}
@@ -67,7 +70,7 @@ func populate[DBType any](ctx context.Context, g *Generator, name string, seed D
6770
})
6871
v, ok := out[name].(DBType)
6972
if !ok {
70-
panic("developer error, type mismatch")
73+
g.testT.Fatalf("developer error, type mismatch in data generator")
7174
}
7275
return v
7376
}

0 commit comments

Comments
 (0)