forked from DATA-DOG/go-sqlmock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expectations_test.go
47 lines (37 loc) · 1.19 KB
/
expectations_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
package sqlmock
import (
"database/sql/driver"
"testing"
"time"
)
func TestQueryExpectationArgComparison(t *testing.T) {
e := &queryBasedExpectation{}
against := []driver.Value{5}
if !e.argsMatches(against) {
t.Error("arguments should match, since the no expectation was set")
}
e.args = []driver.Value{5, "str"}
against = []driver.Value{5}
if e.argsMatches(against) {
t.Error("arguments should not match, since the size is not the same")
}
against = []driver.Value{3, "str"}
if e.argsMatches(against) {
t.Error("arguments should not match, since the first argument (int value) is different")
}
against = []driver.Value{5, "st"}
if e.argsMatches(against) {
t.Error("arguments should not match, since the second argument (string value) is different")
}
against = []driver.Value{5, "str"}
if !e.argsMatches(against) {
t.Error("arguments should match, but it did not")
}
e.args = []driver.Value{5, time.Now()}
const longForm = "Jan 2, 2006 at 3:04pm (MST)"
tm, _ := time.Parse(longForm, "Feb 3, 2013 at 7:54pm (PST)")
against = []driver.Value{5, tm}
if !e.argsMatches(against) {
t.Error("arguments should match (time will be compared only by type), but it did not")
}
}