Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
BrunoQuaresma committed Sep 16, 2024
commit 0e55b09e4998c057ee9e72bdef8cbb0d2ea93046
12 changes: 9 additions & 3 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,9 @@ func (q *FakeQuerier) GetProvisionerJobTimingsByJobID(_ context.Context, jobID u
if len(timings) == 0 {
return nil, sql.ErrNoRows
}
sort.Slice(timings, func(i, j int) bool {
return timings[i].StartedAt.Before(timings[j].StartedAt)
})

return timings, nil
}
Expand Down Expand Up @@ -6804,19 +6807,22 @@ func (q *FakeQuerier) InsertProvisionerJobTimings(_ context.Context, arg databas
q.mutex.Lock()
defer q.mutex.Unlock()

insertedTimings := make([]database.ProvisionerJobTiming, 0, len(arg.StartedAt))
for i := range arg.StartedAt {
q.provisionerJobTimings = append(q.provisionerJobTimings, database.ProvisionerJobTiming{
timing := database.ProvisionerJobTiming{
JobID: arg.JobID,
StartedAt: arg.StartedAt[i],
EndedAt: arg.EndedAt[i],
Stage: arg.Stage[i],
Source: arg.Source[i],
Action: arg.Action[i],
Resource: arg.Resource[i],
})
}
q.provisionerJobTimings = append(q.provisionerJobTimings, timing)
insertedTimings = append(insertedTimings, timing)
}

return q.provisionerJobTimings, nil
return insertedTimings, nil
}

func (q *FakeQuerier) InsertProvisionerKey(_ context.Context, arg database.InsertProvisionerKeyParams) (database.ProvisionerKey, error) {
Expand Down
22 changes: 10 additions & 12 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3694,10 +3694,7 @@ func TestWorkspaceTimings(t *testing.T) {
t.Parallel()

// Generate timings based on test config
generatedTimings := make([]database.ProvisionerJobTiming, tc.provisionerTimings)
if tc.provisionerTimings > 0 {
generatedTimings = makeProvisionerTimings(tc.workspace.build.JobID, tc.provisionerTimings)
}
generatedTimings := makeProvisionerTimings(tc.workspace.build.JobID, tc.provisionerTimings)
res, err := client.WorkspaceTimings(context.Background(), tc.workspace.ID)

// When error is expected, than an error is returned
Expand All @@ -3709,16 +3706,17 @@ func TestWorkspaceTimings(t *testing.T) {
// When success is expected, than no error is returned and the length and
// fields are correctly returned
require.NoError(t, err)
require.Len(t, res, tc.provisionerTimings)
require.Len(t, res.ProvisionerTimings, tc.provisionerTimings)
for i := range res.ProvisionerTimings {
timingRes := res.ProvisionerTimings[i]
require.Equal(t, generatedTimings[i].Resource, timingRes.Resource)
require.Equal(t, generatedTimings[i].Action, timingRes.Action)
require.Equal(t, generatedTimings[i].Stage, timingRes.Stage)
require.Equal(t, generatedTimings[i].JobID, timingRes.JobID)
require.Equal(t, generatedTimings[i].Source, timingRes.Source)
require.Equal(t, generatedTimings[i].StartedAt.UnixMilli(), timingRes.StartedAt.UnixMilli())
require.Equal(t, generatedTimings[i].EndedAt.UnixMilli(), timingRes.EndedAt.UnixMilli())
genTiming := generatedTimings[i]
require.Equal(t, genTiming.Resource, timingRes.Resource)
require.Equal(t, genTiming.Action, timingRes.Action)
require.Equal(t, string(genTiming.Stage), timingRes.Stage)
require.Equal(t, genTiming.JobID.String(), timingRes.JobID.String())
require.Equal(t, genTiming.Source, timingRes.Source)
require.Equal(t, genTiming.StartedAt.UnixMilli(), timingRes.StartedAt.UnixMilli())
require.Equal(t, genTiming.EndedAt.UnixMilli(), timingRes.EndedAt.UnixMilli())
}
})
}
Expand Down
Loading