-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
43 lines (38 loc) · 948 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
package gosqle
import (
"strings"
"testing"
"github.com/dwethmar/gosqle/expressions"
"github.com/dwethmar/gosqle/logic"
"github.com/dwethmar/gosqle/mysql"
"github.com/dwethmar/gosqle/predicates"
)
func TestDelete_Write(t *testing.T) {
tests := []struct {
name string
delete *Delete
want string
wantErr bool
}{
{
name: "delete from",
delete: NewDelete("users").Where(
logic.And(predicates.EQ(expressions.Column{Name: "id", From: "users"}, mysql.NewArgument(1))),
),
want: "DELETE FROM users WHERE users.id = ?;",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sb := new(strings.Builder)
err := tt.delete.Write(sb)
if (err != nil) != tt.wantErr {
t.Errorf("Delete.Write() error = %v, wantErr %v", err, tt.wantErr)
return
}
if query := sb.String(); query != tt.want {
t.Errorf("Delete.Write() query = %q, wantQuery %q", query, tt.want)
}
})
}
}