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

Function TestBatchUpsertConnectionLogs

coderd/database/querier_test.go:3904–4455  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3902}
3903
3904func 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},

Callers

nothing calls this directly

Calls 15

UserFunction · 0.92
OrganizationFunction · 0.92
TemplateFunction · 0.92
WorkspaceFunction · 0.92
NewDBFunction · 0.92
NowFunction · 0.92
DurationMethod · 0.80
HelperMethod · 0.65
NewMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected