@@ -6,8 +6,101 @@ import (
66 "database/sql"
77 "database/sql/driver"
88 "testing"
9+ "time"
910)
1011
12+ func TestQueryExpectationArgComparison (t * testing.T ) {
13+ e := & queryBasedExpectation {converter : driver .DefaultParameterConverter }
14+ against := []driver.NamedValue {{Value : int64 (5 ), Ordinal : 1 }}
15+ if err := e .argsMatches (against ); err != nil {
16+ t .Errorf ("arguments should match, since the no expectation was set, but got err: %s" , err )
17+ }
18+
19+ e .args = []driver.Value {5 , "str" }
20+
21+ against = []driver.NamedValue {{Value : int64 (5 ), Ordinal : 1 }}
22+ if err := e .argsMatches (against ); err == nil {
23+ t .Error ("arguments should not match, since the size is not the same" )
24+ }
25+
26+ against = []driver.NamedValue {
27+ {Value : int64 (3 ), Ordinal : 1 },
28+ {Value : "str" , Ordinal : 2 },
29+ }
30+ if err := e .argsMatches (against ); err == nil {
31+ t .Error ("arguments should not match, since the first argument (int value) is different" )
32+ }
33+
34+ against = []driver.NamedValue {
35+ {Value : int64 (5 ), Ordinal : 1 },
36+ {Value : "st" , Ordinal : 2 },
37+ }
38+ if err := e .argsMatches (against ); err == nil {
39+ t .Error ("arguments should not match, since the second argument (string value) is different" )
40+ }
41+
42+ against = []driver.NamedValue {
43+ {Value : int64 (5 ), Ordinal : 1 },
44+ {Value : "str" , Ordinal : 2 },
45+ }
46+ if err := e .argsMatches (against ); err != nil {
47+ t .Errorf ("arguments should match, but it did not: %s" , err )
48+ }
49+
50+ const longForm = "Jan 2, 2006 at 3:04pm (MST)"
51+ tm , _ := time .Parse (longForm , "Feb 3, 2013 at 7:54pm (PST)" )
52+ e .args = []driver.Value {5 , tm }
53+
54+ against = []driver.NamedValue {
55+ {Value : int64 (5 ), Ordinal : 1 },
56+ {Value : tm , Ordinal : 2 },
57+ }
58+ if err := e .argsMatches (against ); err != nil {
59+ t .Error ("arguments should match, but it did not" )
60+ }
61+
62+ e .args = []driver.Value {5 , AnyArg ()}
63+ if err := e .argsMatches (against ); err != nil {
64+ t .Errorf ("arguments should match, but it did not: %s" , err )
65+ }
66+ }
67+
68+ func TestQueryExpectationArgComparisonBool (t * testing.T ) {
69+ var e * queryBasedExpectation
70+
71+ e = & queryBasedExpectation {args : []driver.Value {true }, converter : driver .DefaultParameterConverter }
72+ against := []driver.NamedValue {
73+ {Value : true , Ordinal : 1 },
74+ }
75+ if err := e .argsMatches (against ); err != nil {
76+ t .Error ("arguments should match, since arguments are the same" )
77+ }
78+
79+ e = & queryBasedExpectation {args : []driver.Value {false }, converter : driver .DefaultParameterConverter }
80+ against = []driver.NamedValue {
81+ {Value : false , Ordinal : 1 },
82+ }
83+ if err := e .argsMatches (against ); err != nil {
84+ t .Error ("arguments should match, since argument are the same" )
85+ }
86+
87+ e = & queryBasedExpectation {args : []driver.Value {true }, converter : driver .DefaultParameterConverter }
88+ against = []driver.NamedValue {
89+ {Value : false , Ordinal : 1 },
90+ }
91+ if err := e .argsMatches (against ); err == nil {
92+ t .Error ("arguments should not match, since argument is different" )
93+ }
94+
95+ e = & queryBasedExpectation {args : []driver.Value {false }, converter : driver .DefaultParameterConverter }
96+ against = []driver.NamedValue {
97+ {Value : true , Ordinal : 1 },
98+ }
99+ if err := e .argsMatches (against ); err == nil {
100+ t .Error ("arguments should not match, since argument is different" )
101+ }
102+ }
103+
11104func TestQueryExpectationNamedArgComparison (t * testing.T ) {
12105 e := & queryBasedExpectation {converter : driver .DefaultParameterConverter }
13106 against := []driver.NamedValue {{Value : int64 (5 ), Name : "id" }}
0 commit comments