-
Notifications
You must be signed in to change notification settings - Fork 0
/
testutils.go
63 lines (58 loc) · 1.32 KB
/
testutils.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
62
63
package main
import (
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgxpool"
"time"
)
func testutilGetlastinsertedwebhookid() (uuid.UUID, error) {
ctx := context.Background()
var err error
var conn *pgxpool.Pool
if conn, err = pgxpool.New(ctx, PostgresUrl); err != nil {
return uuid.Nil, err
}
defer conn.Close()
var id uuid.UUID
var createdAt time.Time
err = conn.QueryRow(ctx, "SELECT id, created_at FROM webhooks ORDER BY created_at DESC LIMIT 1").Scan(&id, &createdAt)
return id, err
}
func testutilCleartables() error {
var err error
ctx := context.Background()
var conn *pgxpool.Pool
if conn, err = pgxpool.New(ctx, PostgresUrl); err != nil {
return err
}
defer conn.Close()
_, err = conn.Exec(ctx, "delete from almanax_mentions")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from discord_mentions")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from almanax_webhooks")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from twitter_webhooks")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from rss_webhooks")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from subscriptions")
if err != nil {
return err
}
_, err = conn.Exec(ctx, "delete from webhooks")
if err != nil {
return err
}
return err
}