Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d7efc1

Browse files
committed
gen, identation
1 parent 54accd6 commit 9d7efc1

File tree

4 files changed

+33
-52
lines changed

4 files changed

+33
-52
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -330,39 +330,30 @@ func (s *MethodTestSuite) TestAuditLogs() {
330330
}
331331

332332
func (s *MethodTestSuite) TestConnectionLogs() {
333-
s.Run("InsertConnectionLog", s.Subtest(func(db database.Store, check *expects) {
333+
createWorkspace := func(t *testing.T, db database.Store) database.WorkspaceTable {
334334
u := dbgen.User(s.T(), db, database.User{})
335335
o := dbgen.Organization(s.T(), db, database.Organization{})
336336
tpl := dbgen.Template(s.T(), db, database.Template{
337337
OrganizationID: o.ID,
338338
CreatedBy: u.ID,
339339
})
340-
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
340+
return dbgen.Workspace(s.T(), db, database.WorkspaceTable{
341341
ID: uuid.New(),
342342
OwnerID: u.ID,
343343
OrganizationID: o.ID,
344344
AutomaticUpdates: database.AutomaticUpdatesNever,
345345
TemplateID: tpl.ID,
346346
})
347+
}
348+
s.Run("InsertConnectionLog", s.Subtest(func(db database.Store, check *expects) {
349+
ws := createWorkspace(s.T(), db)
347350
check.Args(database.InsertConnectionLogParams{
348351
Action: database.ConnectionActionConnect,
349352
WorkspaceID: ws.ID,
350353
}).Asserts(rbac.ResourceConnectionLog, policy.ActionCreate)
351354
}))
352355
s.Run("GetConnectionLogsOffset", s.Subtest(func(db database.Store, check *expects) {
353-
u := dbgen.User(s.T(), db, database.User{})
354-
o := dbgen.Organization(s.T(), db, database.Organization{})
355-
tpl := dbgen.Template(s.T(), db, database.Template{
356-
OrganizationID: o.ID,
357-
CreatedBy: u.ID,
358-
})
359-
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
360-
ID: uuid.New(),
361-
OwnerID: u.ID,
362-
OrganizationID: o.ID,
363-
AutomaticUpdates: database.AutomaticUpdatesNever,
364-
TemplateID: tpl.ID,
365-
})
356+
ws := createWorkspace(s.T(), db)
366357
_ = dbgen.ConnectionLog(s.T(), db, database.ConnectionLog{
367358
Action: database.ConnectionActionConnect,
368359
WorkspaceID: ws.ID,
@@ -376,19 +367,7 @@ func (s *MethodTestSuite) TestConnectionLogs() {
376367
}).Asserts(rbac.ResourceConnectionLog, policy.ActionRead).WithNotAuthorized("nil")
377368
}))
378369
s.Run("GetAuthorizedConnectionLogsOffset", s.Subtest(func(db database.Store, check *expects) {
379-
u := dbgen.User(s.T(), db, database.User{})
380-
o := dbgen.Organization(s.T(), db, database.Organization{})
381-
tpl := dbgen.Template(s.T(), db, database.Template{
382-
OrganizationID: o.ID,
383-
CreatedBy: u.ID,
384-
})
385-
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
386-
ID: uuid.New(),
387-
OwnerID: u.ID,
388-
OrganizationID: o.ID,
389-
AutomaticUpdates: database.AutomaticUpdatesNever,
390-
TemplateID: tpl.ID,
391-
})
370+
ws := createWorkspace(s.T(), db)
392371
_ = dbgen.ConnectionLog(s.T(), db, database.ConnectionLog{
393372
Action: database.ConnectionActionConnect,
394373
WorkspaceID: ws.ID,

coderd/database/migrations/000334_connection_logs.up.sql

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
CREATE TYPE connection_action AS ENUM (
2-
-- SSH actions
3-
'connect',
4-
'disconnect',
5-
-- Workspace App actions
6-
'open',
7-
'close'
2+
-- SSH actions
3+
'connect',
4+
'disconnect',
5+
-- Workspace App actions
6+
'open',
7+
'close'
88
);
99

1010
CREATE TABLE connection_logs (
11-
id uuid NOT NULL,
12-
"time" timestamp with time zone NOT NULL,
13-
organization_id uuid NOT NULL,
14-
workspace_owner_id uuid NOT NULL,
15-
workspace_id uuid NOT NULL REFERENCES workspaces (id) ON DELETE SET NULL,
16-
workspace_name text NOT NULL,
17-
agent_name text NOT NULL,
18-
action connection_action NOT NULL,
19-
code integer NOT NULL,
11+
id uuid NOT NULL,
12+
"time" timestamp with time zone NOT NULL,
13+
organization_id uuid NOT NULL,
14+
workspace_owner_id uuid NOT NULL,
15+
workspace_id uuid NOT NULL REFERENCES workspaces (id) ON DELETE SET NULL,
16+
workspace_name text NOT NULL,
17+
agent_name text NOT NULL,
18+
action connection_action NOT NULL,
19+
code integer NOT NULL,
2020
ip inet,
2121

2222
-- Null for SSH actions.
23-
user_agent text,
23+
user_agent text,
2424
user_id uuid NOT NULL, -- Can be NULL, but must be uuid.Nil.
2525
slug_or_port text,
2626

2727
-- Null for Workspace App actions.
2828
connection_type text,
2929
reason text,
3030

31-
PRIMARY KEY (id)
31+
PRIMARY KEY (id)
3232
);
3333

3434
COMMENT ON COLUMN connection_logs.code IS 'Either the HTTP status code for the workspace app request, or the exit code of an SSH connection.';

coderd/database/queries/connectionlogs.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ WHERE TRUE
1616
ORDER BY
1717
"time" DESC
1818
LIMIT
19-
-- a limit of 0 means "no limit". The connection log table is unbounded
20-
-- in size, and is expected to be quite large. Implement a default
21-
-- limit of 100 to prevent accidental excessively large queries.
19+
-- a limit of 0 means "no limit". The connection log table is unbounded
20+
-- in size, and is expected to be quite large. Implement a default
21+
-- limit of 100 to prevent accidental excessively large queries.
2222
COALESCE(NULLIF(@limit_opt :: int, 0), 100)
2323
OFFSET
2424
@offset_opt;
@@ -27,9 +27,9 @@ OFFSET
2727
-- name: InsertConnectionLog :one
2828
INSERT INTO
2929
connection_logs (
30-
id,
31-
"time",
32-
organization_id,
30+
id,
31+
"time",
32+
organization_id,
3333
workspace_owner_id,
3434
workspace_id,
3535
workspace_name,
@@ -42,6 +42,6 @@ INSERT INTO
4242
slug_or_port,
4343
connection_type,
4444
reason
45-
)
45+
)
4646
VALUES
4747
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *;

site/src/api/typesGenerated.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)