MCPcopy Index your code
hub / github.com/coder/coder / TestConnectionLogs

Function TestConnectionLogs

enterprise/coderd/connectionlog_test.go:23–255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestConnectionLogs(t *testing.T) {
24 t.Parallel()
25
26 createWorkspace := func(t *testing.T, db database.Store) database.WorkspaceTable {
27 u := dbgen.User(t, db, database.User{})
28 o := dbgen.Organization(t, db, database.Organization{})
29 tpl := dbgen.Template(t, db, database.Template{
30 OrganizationID: o.ID,
31 CreatedBy: u.ID,
32 })
33 return dbgen.Workspace(t, db, database.WorkspaceTable{
34 ID: uuid.New(),
35 OwnerID: u.ID,
36 OrganizationID: o.ID,
37 AutomaticUpdates: database.AutomaticUpdatesNever,
38 TemplateID: tpl.ID,
39 })
40 }
41
42 t.Run("OK", func(t *testing.T) {
43 t.Parallel()
44
45 ctx := context.Background()
46 client, db, _ := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
47 ConnectionLogging: true,
48 LicenseOptions: &coderdenttest.LicenseOptions{
49 Features: license.Features{
50 codersdk.FeatureAuditLog: 1,
51 codersdk.FeatureConnectionLog: 1,
52 },
53 },
54 })
55
56 ws := createWorkspace(t, db)
57 _ = dbgen.ConnectionLog(t, db, database.UpsertConnectionLogParams{
58 Type: database.ConnectionTypeSsh,
59 WorkspaceID: ws.ID,
60 OrganizationID: ws.OrganizationID,
61 WorkspaceOwnerID: ws.OwnerID,
62 })
63
64 logs, err := client.ConnectionLogs(ctx, codersdk.ConnectionLogsRequest{})
65 require.NoError(t, err)
66
67 require.Len(t, logs.ConnectionLogs, 1)
68 require.EqualValues(t, 1, logs.Count)
69 require.Equal(t, codersdk.ConnectionTypeSSH, logs.ConnectionLogs[0].Type)
70 })
71
72 t.Run("Empty", func(t *testing.T) {
73 t.Parallel()
74
75 ctx := context.Background()
76 client, _, _ := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
77 ConnectionLogging: true,
78 LicenseOptions: &coderdenttest.LicenseOptions{
79 Features: license.Features{
80 codersdk.FeatureAuditLog: 1,

Callers

nothing calls this directly

Calls 15

UserFunction · 0.92
OrganizationFunction · 0.92
TemplateFunction · 0.92
WorkspaceFunction · 0.92
NewWithDatabaseFunction · 0.92
ConnectionLogFunction · 0.92
NowFunction · 0.92
NewMethod · 0.65
RunMethod · 0.65
AddMethod · 0.65
createWorkspaceFunction · 0.50
ConnectionLogsMethod · 0.45

Tested by

no test coverage detected