-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhelper_test.go
More file actions
42 lines (35 loc) · 967 Bytes
/
helper_test.go
File metadata and controls
42 lines (35 loc) · 967 Bytes
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
package postgres
import (
"context"
"testing"
"time"
"github.com/henvic/pgxtutorial/inventory"
)
func createProducts(t testing.TB, db DB, products []inventory.CreateProductParams) {
for _, p := range products {
if err := db.CreateProduct(context.Background(), p); err != nil {
t.Errorf("DB.CreateProduct() error = %v", err)
}
}
}
func createProductReviews(t testing.TB, db DB, reviews []inventory.CreateProductReviewDBParams) {
for _, r := range reviews {
if err := db.CreateProductReview(context.Background(), r); err != nil {
t.Errorf("DB.CreateProductReview() error = %v", err)
}
}
}
func canceledContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
cancel()
return ctx
}
func deadlineExceededContext() context.Context {
ctx, cancel := context.WithTimeout(context.Background(), -time.Second)
cancel()
return ctx
}
// ptr returns a pointer to the given value.
func ptr[T any](v T) *T {
return &v
}