Skip to content

Commit 2ddb544

Browse files
committed
Fix unit test job tags
1 parent 113bcb2 commit 2ddb544

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

coderd/database/db2sdk/db2sdk_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/rand"
55
"database/sql"
66
"encoding/json"
7+
"fmt"
78
"testing"
89
"time"
910

@@ -117,8 +118,9 @@ func TestProvisionerJobStatus(t *testing.T) {
117118
db, _ := dbtestutil.NewDB(t)
118119
org := dbgen.Organization(t, db, database.Organization{})
119120

120-
for _, tc := range cases {
121+
for i, tc := range cases {
121122
tc := tc
123+
i := i
122124
t.Run(tc.name, func(t *testing.T) {
123125
t.Parallel()
124126
// Populate standard fields
@@ -130,6 +132,8 @@ func TestProvisionerJobStatus(t *testing.T) {
130132
tc.job.OrganizationID = org.ID
131133
tc.job.Input = []byte("{}")
132134
tc.job.Provisioner = database.ProvisionerTypeEcho
135+
// Unique tags for each job.
136+
tc.job.Tags = map[string]string{fmt.Sprintf("%d", i): "true"}
133137

134138
inserted := dbgen.ProvisionerJob(t, db, nil, tc.job)
135139
// Make sure the inserted job has the right values.

coderd/database/dbgen/dbgen.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,16 @@ func GroupMember(t testing.TB, db database.Store, orig database.GroupMember) dat
328328
// ProvisionerJob is a bit more involved to get the values such as "completedAt", "startedAt", "cancelledAt" set. ps
329329
// can be set to nil if you are SURE that you don't require a provisionerdaemon to acquire the job in your test.
330330
func ProvisionerJob(t testing.TB, db database.Store, ps pubsub.Pubsub, orig database.ProvisionerJob) database.ProvisionerJob {
331-
id := takeFirst(orig.ID, uuid.New())
331+
jobID := takeFirst(orig.ID, uuid.New())
332332
// Always set some tags to prevent Acquire from grabbing jobs it should not.
333333
if !orig.StartedAt.Time.IsZero() {
334334
if orig.Tags == nil {
335335
orig.Tags = make(database.StringMap)
336336
}
337337
// Make sure when we acquire the job, we only get this one.
338-
orig.Tags[id.String()] = "true"
338+
orig.Tags[jobID.String()] = "true"
339339
}
340-
jobID := takeFirst(orig.ID, uuid.New())
340+
341341
job, err := db.InsertProvisionerJob(genCtx, database.InsertProvisionerJobParams{
342342
ID: jobID,
343343
CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()),
@@ -365,6 +365,11 @@ func ProvisionerJob(t testing.TB, db database.Store, ps pubsub.Pubsub, orig data
365365
WorkerID: uuid.NullUUID{},
366366
})
367367
require.NoError(t, err)
368+
if job.ID != jobID {
369+
fmt.Println("wtf")
370+
}
371+
// There is no easy way to make sure we aquire the correct job.
372+
require.Equal(t, jobID, job.ID, "acquired incorrect job")
368373
}
369374

370375
if !orig.CompletedAt.Time.IsZero() || orig.Error.String != "" {

coderd/provisionerjobs_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func Test_logFollower_completeBeforeSubscribe(t *testing.T) {
248248
Time: now.Add(-time.Millisecond),
249249
Valid: true,
250250
},
251-
JobStatus: database.ProvisionerJobStatusRunning,
251+
JobStatus: database.ProvisionerJobStatusSucceeded,
252252
},
253253
nil,
254254
)

site/src/pages/TemplateVersionEditorPage/TemplateVersionStatusBadge.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const getStatus = (
5656
text: "Canceled",
5757
icon: <ErrorIcon />,
5858
};
59+
case "unknown":
5960
case "failed":
6061
return {
6162
type: "error",

site/src/utils/workspace.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,9 @@ export const getDisplayWorkspaceBuildStatus = (
5151
color: theme.palette.primary.main,
5252
status: DisplayWorkspaceBuildStatusLanguage.running,
5353
} as const;
54-
case "failed":
55-
return {
56-
type: "error",
57-
color: theme.palette.text.secondary,
58-
status: DisplayWorkspaceBuildStatusLanguage.failed,
59-
} as const;
6054
// Just handle unknown as failed
6155
case "unknown":
56+
case "failed":
6257
return {
6358
type: "error",
6459
color: theme.palette.text.secondary,

0 commit comments

Comments
 (0)