-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_test.go
79 lines (65 loc) · 1.64 KB
/
select_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
package sqlwrap_test
import (
"context"
"github.com/jtarchie/sqlwrap"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Select", func() {
var client *sqlwrap.Client
BeforeEach(func() {
var err error
client, err = createClient()
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
err := client.Close()
Expect(err).NotTo(HaveOccurred())
})
It("bind with named parameters", func() {
var firstNames []string
err := client.Select(
context.Background(),
&firstNames,
"SELECT first_name FROM people WHERE last_name = :last_name",
map[string]interface{}{
"last_name": "Smith",
},
)
Expect(err).NotTo(HaveOccurred())
Expect(firstNames).To(Equal([]string{"Bob", "Jane"}))
})
It("errors when binding is missing", func() {
var firstNames []string
err := client.Select(
context.Background(),
&firstNames,
"SELECT first_name FROM people WHERE last_name = :last_name",
map[string]interface{}{},
)
Expect(err).To(HaveOccurred())
})
It("can handle IN clauses", func() {
var firstNames []string
err := client.Select(
context.Background(),
&firstNames,
"SELECT first_name FROM people WHERE email IN (:email)",
map[string]interface{}{
"email": sqlwrap.Values{"bob@smith.com"},
},
)
Expect(err).NotTo(HaveOccurred())
Expect(firstNames).To(Equal([]string{"Bob"}))
})
It("errors with missing params of IN clauses", func() {
var firstNames []string
err := client.Select(
context.Background(),
&firstNames,
"SELECT first_name FROM people WHERE email IN (:email)",
map[string]interface{}{},
)
Expect(err).To(HaveOccurred())
})
})