(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func 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, |
nothing calls this directly
no test coverage detected