forked from bgentry/que-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathque_test.go
61 lines (53 loc) · 1.1 KB
/
que_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package que
import (
"testing"
"github.com/jackc/pgx"
)
var testConnConfig = pgx.ConnConfig{
Host: "localhost",
Database: "que-go-test",
}
func openTestClientMaxConns(t testing.TB, maxConnections int) *Client {
connPoolConfig := pgx.ConnPoolConfig{
ConnConfig: testConnConfig,
MaxConnections: maxConnections,
AfterConnect: PrepareStatements,
}
pool, err := pgx.NewConnPool(connPoolConfig)
if err != nil {
t.Fatal(err)
}
return NewClient(pool)
}
func openTestClient(t testing.TB) *Client {
return openTestClientMaxConns(t, 5)
}
func truncateAndClose(pool *pgx.ConnPool) {
if _, err := pool.Exec("TRUNCATE TABLE que_jobs"); err != nil {
panic(err)
}
pool.Close()
}
func findOneJob(q queryable) (*Job, error) {
findSQL := `
SELECT priority, run_at, job_id, job_class, args, error_count, last_error, queue
FROM que_jobs LIMIT 1`
j := &Job{}
err := q.QueryRow(findSQL).Scan(
&j.Priority,
&j.RunAt,
&j.ID,
&j.Type,
&j.Args,
&j.ErrorCount,
&j.LastError,
&j.Queue,
)
if err == pgx.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return j, nil
}