-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_setup.go
54 lines (44 loc) · 1.07 KB
/
test_setup.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
package transferspg
import (
"context"
"time"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/jpgsaraceni/suricate-bank/app/domain/entities/account"
"github.com/jpgsaraceni/suricate-bank/app/domain/entities/transfer"
"github.com/jpgsaraceni/suricate-bank/app/vos/money"
)
const (
testAmount10 = 10
testAmount15 = 15
)
var (
testContext = context.Background()
testTime = time.Now().Round(time.Hour)
testMoney10, _ = money.NewMoney(testAmount10)
testMoney15, _ = money.NewMoney(testAmount15)
)
func createTestTransferBatch(pool *pgxpool.Pool, ids []transfer.ID, originIds, destinationIds []account.ID, amount []int) error {
const query = `
INSERT INTO
transfers (
id,
account_origin_id,
account_destination_id,
amount,
created_at
)
VALUES
($1, $2, $3, $4, $5);
`
batch := &pgx.Batch{}
for i := 0; i < len(ids); i++ {
batch.Queue(query, ids[i], originIds[i], destinationIds[i], amount[i], testTime)
}
br := pool.SendBatch(testContext, batch)
if _, err := br.Exec(); err != nil {
return err
}
br.Close()
return nil
}