Skip to content

Commit afe37c9

Browse files
committed
make fmt and linter happy
Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 02d84bd commit afe37c9

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

coderd/agentapi/cached_workspace.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package agentapi
22

33
import (
4-
"sync"
54
"database/sql"
5+
"sync"
66

77
"github.com/google/uuid"
88

@@ -36,6 +36,17 @@ type CachedWorkspaceFields struct {
3636
AutostartSchedule sql.NullString
3737
}
3838

39+
func (cws *CachedWorkspaceFields) Equal(cws2 *CachedWorkspaceFields) bool {
40+
cws.lock.RLock()
41+
defer cws.lock.RUnlock()
42+
cws2.lock.RLock()
43+
defer cws2.lock.RUnlock()
44+
45+
return cws.ID == cws2.ID && cws.OwnerID == cws2.OwnerID && cws.OrganizationID == cws2.OrganizationID &&
46+
cws.TemplateID == cws2.TemplateID && cws.Name == cws2.Name && cws.OwnerUsername == cws2.OwnerUsername &&
47+
cws.TemplateName == cws2.TemplateName && cws.AutostartSchedule == cws2.AutostartSchedule
48+
}
49+
3950
func (cws *CachedWorkspaceFields) Clear() {
4051
cws.lock.Lock()
4152
defer cws.lock.Unlock()
@@ -64,7 +75,7 @@ func (cws *CachedWorkspaceFields) UpdateValues(ws database.Workspace) {
6475

6576
func (cws *CachedWorkspaceFields) AsDatabaseWorkspace() database.Workspace {
6677
cws.lock.RLock()
67-
defer cws.lock.RUnlock()
78+
defer cws.lock.RUnlock()
6879
return database.Workspace{
6980
ID: cws.ID,
7081
OwnerID: cws.OwnerID,

coderd/agentapi/cached_workspace_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package agentapi_test
22

3-
import(
3+
import (
44
"testing"
55

6-
"github.com/stretchr/testify/require"
76
"github.com/google/uuid"
7+
"github.com/stretchr/testify/require"
88

99
"github.com/coder/coder/v2/coderd/agentapi"
1010
"github.com/coder/coder/v2/coderd/database"
1111
)
1212

1313
func TestCacheClear(t *testing.T) {
14+
t.Parallel()
15+
1416
var (
1517
user = database.User{
1618
ID: uuid.New(),
@@ -41,10 +43,12 @@ func TestCacheClear(t *testing.T) {
4143

4244
emptyCws := agentapi.CachedWorkspaceFields{}
4345
workspaceAsCacheFields.Clear()
44-
require.Equal(t, emptyCws, workspaceAsCacheFields)
46+
require.True(t, emptyCws.Equal(&workspaceAsCacheFields))
4547
}
4648

4749
func TestCacheUpdate(t *testing.T) {
50+
t.Parallel()
51+
4852
var (
4953
user = database.User{
5054
ID: uuid.New(),
@@ -75,5 +79,5 @@ func TestCacheUpdate(t *testing.T) {
7579

7680
cws := agentapi.CachedWorkspaceFields{}
7781
cws.UpdateValues(workspace)
78-
require.Equal(t, workspaceAsCacheFields, cws)
82+
require.True(t, workspaceAsCacheFields.Equal(&cws))
7983
}

coderd/agentapi/stats_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ func TestUpdateStates(t *testing.T) {
339339
},
340340
}
341341
)
342-
// need to overwrite the cached fields for this test
343-
ws := workspaceAsCacheFields
342+
// need to overwrite the cached fields for this test, but the struct has a lock
343+
ws := agentapi.CachedWorkspaceFields{}
344+
ws.UpdateValues(workspace)
344345
ws.AutostartSchedule = workspace.AutostartSchedule
345346

346347
api := agentapi.StatsAPI{

0 commit comments

Comments
 (0)