Refactor connection listing for tests (#1224)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-05-14 15:57:15 -04:00
1 parent ea611b4f6a
commit b47b71d26c
3 files changed
+13 -18

No files matched your search

+7 -13
View File
@@ -44,21 +44,15 @@ func (r *Repository) LookupConnection(ctx context.Context, connectionId string,
return &connection, states, nil
}
// ListConnections will connections by session ID. If session ID is *, all
// connections are returned. Supports the WithLimit and WithOrder options.
// ListConnectionsBySessionId will list connections by session ID. Supports the
// WithLimit and WithOrder options.
func (r *Repository) ListConnectionsBySessionId(ctx context.Context, sessionId string, opt ...Option) ([]*Connection, error) {
const op = "session.(Repository).ListConnections"
opts := getOpts(opt...)
var connections []*Connection
var args []interface{}
var where string
if sessionId != "*" {
where = "session_id = ?"
args = append(args, sessionId)
const op = "session.(Repository).ListConnectionsBySessionId"
if sessionId == "" {
return nil, errors.New(errors.InvalidParameter, op, "no session ID supplied")
}
// The where clause will be ignored if args is empty, if we don't want to
// scope to a specific session ID
err := r.list(ctx, &connections, where, args, opts) // pass options, so WithLimit and WithOrder are supported
var connections []*Connection
err := r.list(ctx, &connections, "session_id = ?", []interface{}{sessionId}, opt...) // pass options, so WithLimit and WithOrder are supported
if err != nil {
return nil, errors.Wrap(err, op)
}