(t *testing.T)
| 3902 | } |
| 3903 | |
| 3904 | func TestBatchUpsertConnectionLogs(t *testing.T) { |
| 3905 | t.Parallel() |
| 3906 | |
| 3907 | createWorkspace := func(t *testing.T, db database.Store) database.WorkspaceTable { |
| 3908 | t.Helper() |
| 3909 | u := dbgen.User(t, db, database.User{}) |
| 3910 | o := dbgen.Organization(t, db, database.Organization{}) |
| 3911 | tpl := dbgen.Template(t, db, database.Template{ |
| 3912 | OrganizationID: o.ID, |
| 3913 | CreatedBy: u.ID, |
| 3914 | }) |
| 3915 | return dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 3916 | ID: uuid.New(), |
| 3917 | OwnerID: u.ID, |
| 3918 | OrganizationID: o.ID, |
| 3919 | AutomaticUpdates: database.AutomaticUpdatesNever, |
| 3920 | TemplateID: tpl.ID, |
| 3921 | }) |
| 3922 | } |
| 3923 | |
| 3924 | // zeroTime is the sentinel value that the SQL treats as "no |
| 3925 | // connect/disconnect time provided". |
| 3926 | zeroTime := time.Time{} |
| 3927 | |
| 3928 | defaultIP := pqtype.Inet{ |
| 3929 | IPNet: net.IPNet{ |
| 3930 | IP: net.IPv4(127, 0, 0, 1), |
| 3931 | Mask: net.IPv4Mask(255, 255, 255, 255), |
| 3932 | }, |
| 3933 | Valid: true, |
| 3934 | } |
| 3935 | |
| 3936 | t.Run("SingleConnect", func(t *testing.T) { |
| 3937 | t.Parallel() |
| 3938 | db, _ := dbtestutil.NewDB(t) |
| 3939 | ctx := context.Background() |
| 3940 | ws := createWorkspace(t, db) |
| 3941 | connID := uuid.New() |
| 3942 | connectTime := dbtime.Now() |
| 3943 | |
| 3944 | err := db.BatchUpsertConnectionLogs(ctx, database.BatchUpsertConnectionLogsParams{ |
| 3945 | ID: []uuid.UUID{uuid.New()}, |
| 3946 | ConnectTime: []time.Time{connectTime}, |
| 3947 | OrganizationID: []uuid.UUID{ws.OrganizationID}, |
| 3948 | WorkspaceOwnerID: []uuid.UUID{ws.OwnerID}, |
| 3949 | WorkspaceID: []uuid.UUID{ws.ID}, |
| 3950 | WorkspaceName: []string{ws.Name}, |
| 3951 | AgentName: []string{"agent"}, |
| 3952 | Type: []database.ConnectionType{database.ConnectionTypeSsh}, |
| 3953 | Code: []int32{0}, |
| 3954 | CodeValid: []bool{false}, |
| 3955 | Ip: []pqtype.Inet{defaultIP}, |
| 3956 | UserAgent: []string{""}, |
| 3957 | UserID: []uuid.UUID{uuid.Nil}, |
| 3958 | SlugOrPort: []string{""}, |
| 3959 | ConnectionID: []uuid.UUID{connID}, |
| 3960 | DisconnectReason: []string{""}, |
| 3961 | DisconnectTime: []time.Time{zeroTime}, |
nothing calls this directly
no test coverage detected