-
Notifications
You must be signed in to change notification settings - Fork 27
/
query.sql_test.go
100 lines (88 loc) · 2.59 KB
/
query.sql_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package composite
import (
"context"
"github.com/jackc/pgtype"
"github.com/jschaf/pggen/internal/difftest"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/jschaf/pggen/internal/ptrs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestNewQuerier_SearchScreenshots(t *testing.T) {
conn, cleanup := pgtest.NewPostgresSchema(t, []string{"schema.sql"})
defer cleanup()
q := NewQuerier(conn)
screenshotID := 99
screenshot1 := insertScreenshotBlock(t, q, screenshotID, "body1")
screenshot2 := insertScreenshotBlock(t, q, screenshotID, "body2")
want := []SearchScreenshotsRow{
{
ID: screenshotID,
Blocks: []Blocks{
{
ID: screenshot1.ID,
ScreenshotID: screenshotID,
Body: screenshot1.Body,
},
{
ID: screenshot2.ID,
ScreenshotID: screenshotID,
Body: screenshot2.Body,
},
},
},
}
t.Run("SearchScreenshots", func(t *testing.T) {
rows, err := q.SearchScreenshots(context.Background(), SearchScreenshotsParams{
Body: "body",
Limit: 5,
Offset: 0,
})
require.NoError(t, err)
assert.Equal(t, want, rows)
})
t.Run("SearchScreenshotsOneCol", func(t *testing.T) {
rows, err := q.SearchScreenshotsOneCol(context.Background(), SearchScreenshotsOneColParams{
Body: "body",
Limit: 5,
Offset: 0,
})
require.NoError(t, err)
assert.Equal(t, [][]Blocks{want[0].Blocks}, rows)
})
}
func TestNewQuerier_ArraysInput(t *testing.T) {
conn, cleanup := pgtest.NewPostgresSchema(t, []string{"schema.sql"})
defer cleanup()
q := NewQuerier(conn)
t.Run("ArraysInput", func(t *testing.T) {
want := Arrays{
Texts: []string{"foo", "bar"},
Int8s: []*int{ptrs.Int(1), ptrs.Int(2), ptrs.Int(3)},
Bools: []bool{true, true, false},
Floats: []*float64{ptrs.Float64(33.3), ptrs.Float64(66.6)},
}
got, err := q.ArraysInput(context.Background(), want)
require.NoError(t, err)
difftest.AssertSame(t, want, got)
})
}
func TestNewQuerier_UserEmails(t *testing.T) {
conn, cleanup := pgtest.NewPostgresSchema(t, []string{"schema.sql"})
defer cleanup()
q := NewQuerier(conn)
got, err := q.UserEmails(context.Background())
require.NoError(t, err)
want := UserEmail{
ID: "foo",
Email: pgtype.Text{String: "[email protected]", Status: pgtype.Present},
}
difftest.AssertSame(t, want, got)
}
func insertScreenshotBlock(t *testing.T, q *DBQuerier, screenID int, body string) InsertScreenshotBlocksRow {
t.Helper()
row, err := q.InsertScreenshotBlocks(context.Background(), screenID, body)
require.NoError(t, err, "insert screenshot blocks")
return row
}