testing.go

 1package backend
 2
 3// InsertWorkspaceForTest registers ws with b under its current ID and
 4// path. It is intended for tests in other packages that need to drive
 5// HTTP handlers against a synthetic workspace without booting a real
 6// app.App. Production code should go through CreateWorkspace.
 7func InsertWorkspaceForTest(b *Backend, ws *Workspace) {
 8	if ws.resolvedPath == "" {
 9		ws.resolvedPath = ws.Path
10	}
11	if ws.clients == nil {
12		ws.clients = make(map[string]*clientState)
13	}
14	b.mu.Lock()
15	defer b.mu.Unlock()
16	b.workspaces.Set(ws.ID, ws)
17	if ws.resolvedPath != "" {
18		b.pathIndex[ws.resolvedPath] = ws.ID
19	}
20}