-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_test.go
45 lines (34 loc) · 946 Bytes
/
delete_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
package database
import (
"database/sql/driver"
"testing"
"github.com/stretchr/testify/assert"
"github.com/DATA-DOG/go-sqlmock"
)
func TestDelete(t *testing.T) {
conn := &MockConnection{}
err := conn.Connect()
assert.Nil(t, err, "failed to connect to db instance")
defer conn.Close()
// DELETE FROM fire_teams WHERE ( _id = 'bravo' );
delString := `DELETE FROM fire_teams WHERE ( _id = $1 );`
delArgs := []driver.Value{`foxtrot`}
query1, err := NewQuery(conn)
assert.Nil(t, err)
mock := conn.GetMock()
mock.ExpectPrepare(delString).WillBeClosed()
mock.ExpectExec(delString).WithArgs(delArgs...).WillReturnResult(sqlmock.NewResult(0, 1))
count, err := query1.For("fire_teams").Where([]Condition{{
Nested: &WhereGroup{
Conditions: []Condition{
{
Field: "_id",
Operator: "=",
Values: []any{"foxtrot"},
},
},
},
}}).Delete()
assert.Nil(t, err)
assert.Equal(t, int64(1), count)
}