Skip to content

Commit 13a4fab

Browse files
committed
chore: Add WorkspaceApps to dbgen
1 parent d1b948d commit 13a4fab

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

coderd/database/dbgen/generator.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ func ProvisionerJob(t *testing.T, db database.Store, orig database.ProvisionerJo
254254
return job
255255
}
256256

257+
func WorkspaceApp(t *testing.T, db database.Store, orig database.WorkspaceApp) database.WorkspaceApp {
258+
resource, err := db.InsertWorkspaceApp(context.Background(), database.InsertWorkspaceAppParams{
259+
ID: takeFirst(orig.ID, uuid.New()),
260+
CreatedAt: takeFirst(orig.CreatedAt, time.Now()),
261+
AgentID: takeFirst(orig.AgentID, uuid.New()),
262+
Slug: takeFirst(orig.Slug, namesgenerator.GetRandomName(1)),
263+
DisplayName: takeFirst(orig.DisplayName, namesgenerator.GetRandomName(1)),
264+
Icon: takeFirst(orig.Icon, namesgenerator.GetRandomName(1)),
265+
Command: sql.NullString{
266+
String: takeFirst(orig.Command.String, "ls"),
267+
Valid: orig.Command.Valid,
268+
},
269+
Url: sql.NullString{
270+
String: takeFirst(orig.Url.String),
271+
Valid: orig.Url.Valid,
272+
},
273+
External: orig.External,
274+
Subdomain: orig.Subdomain,
275+
SharingLevel: takeFirst(orig.SharingLevel, database.AppSharingLevelOwner),
276+
HealthcheckUrl: takeFirst(orig.HealthcheckUrl, "https://localhost:8000"),
277+
HealthcheckInterval: takeFirst(orig.HealthcheckInterval, 60),
278+
HealthcheckThreshold: takeFirst(orig.HealthcheckThreshold, 60),
279+
Health: takeFirst(orig.Health, database.WorkspaceAppHealthHealthy),
280+
})
281+
require.NoError(t, err, "insert app")
282+
return resource
283+
}
284+
257285
func WorkspaceResource(t *testing.T, db database.Store, orig database.WorkspaceResource) database.WorkspaceResource {
258286
resource, err := db.InsertWorkspaceResource(context.Background(), database.InsertWorkspaceResourceParams{
259287
ID: takeFirst(orig.ID, uuid.New()),

coderd/database/dbgen/generator_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func TestGenerator(t *testing.T) {
5151
require.Equal(t, exp, must(db.GetWorkspaceResourceByID(context.Background(), exp.ID)))
5252
})
5353

54+
t.Run("WorkspaceApp", func(t *testing.T) {
55+
t.Parallel()
56+
db := dbfake.New()
57+
exp := dbgen.WorkspaceApp(t, db, database.WorkspaceApp{})
58+
require.Equal(t, exp, must(db.GetWorkspaceAppsByAgentID(context.Background(), exp.AgentID))[0])
59+
})
60+
5461
t.Run("WorkspaceResourceMetadatum", func(t *testing.T) {
5562
t.Parallel()
5663
db := dbfake.New()

0 commit comments

Comments
 (0)