Skip to content

Commit 84f4316

Browse files
committed
dbmem implementation
1 parent 38719b1 commit 84f4316

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

coderd/database/dbmem/dbmem.go

+49
Original file line numberDiff line numberDiff line change
@@ -8118,6 +8118,55 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
81188118
continue
81198119
}
81208120

8121+
if len(arg.HasParam) > 0 || len(arg.ParamNames) > 0 {
8122+
build, err := q.getLatestWorkspaceBuildByWorkspaceIDNoLock(ctx, workspace.ID)
8123+
if err != nil {
8124+
return nil, xerrors.Errorf("get latest build: %w", err)
8125+
}
8126+
8127+
params := make([]database.WorkspaceBuildParameter, 0)
8128+
for _, param := range q.workspaceBuildParameters {
8129+
if param.WorkspaceBuildID != build.ID {
8130+
continue
8131+
}
8132+
params = append(params, param)
8133+
}
8134+
8135+
var innerErr error
8136+
index := slices.IndexFunc(params, func(buildParam database.WorkspaceBuildParameter) bool {
8137+
// If hasParam matches, then we are done. This is a good match.
8138+
if slices.ContainsFunc(arg.HasParam, func(name string) bool {
8139+
return strings.EqualFold(buildParam.Name, name)
8140+
}) {
8141+
return true
8142+
}
8143+
8144+
// Check name + value
8145+
match := false
8146+
for i := range arg.ParamNames {
8147+
matchName := arg.ParamNames[i]
8148+
if !strings.EqualFold(matchName, buildParam.Name) {
8149+
continue
8150+
}
8151+
8152+
matchValue := arg.ParamValues[i]
8153+
if !strings.EqualFold(matchValue, buildParam.Value) {
8154+
continue
8155+
}
8156+
match = true
8157+
break
8158+
}
8159+
8160+
return match
8161+
})
8162+
if innerErr != nil {
8163+
return nil, xerrors.Errorf("error searching workspace build params: %w", innerErr)
8164+
}
8165+
if index < 0 {
8166+
continue
8167+
}
8168+
}
8169+
81218170
if arg.OwnerUsername != "" {
81228171
owner, err := q.getUserByIDNoLock(workspace.OwnerID)
81238172
if err == nil && !strings.EqualFold(arg.OwnerUsername, owner.Username) {

0 commit comments

Comments
 (0)