-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_test.go
56 lines (47 loc) · 1.1 KB
/
exec_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
package dbal
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestExec(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
assertion func(*testing.T, string)
}{
{
// db.Prepare errors out because the SQL file is empty
desc: "db.Prepare returned an error",
assertion: func(t *testing.T, desc string) {
// arrangement
d := &dbal{db: &mockDb{PrepareOk: false}}
// act
_, err := d.Exec(badSQLStmnt, nil)
// assertion
require.Error(t, err, desc)
},
},
{
desc: "db.Prepare did not return an error",
assertion: func(t *testing.T, desc string) {
db := testLoadDBAL(t)
defer db.Close()
params := map[string]interface{}{
"first_name": "bearpig",
"last_name": "man",
"address": []byte(`{ "test": "foo" }`),
}
// act
_, qryErr := db.Exec(insertCustomer, params)
// assertion
require.NoError(t, qryErr, desc)
// clean up
_, qryErr = db.Query(deleteCustomer, params)
require.NoError(t, qryErr, desc)
},
},
}
for _, test := range tests {
test.assertion(t, test.desc)
}
}