@@ -10,29 +10,38 @@ import (
1010
1111func TestQueryExpectationArgComparison (t * testing.T ) {
1212 e := & queryBasedExpectation {}
13- against := []driver. Value { int64 (5 )}
13+ against := []namedValue {{ Value : int64 (5 ), Ordinal : 1 } }
1414 if err := e .argsMatches (against ); err != nil {
1515 t .Errorf ("arguments should match, since the no expectation was set, but got err: %s" , err )
1616 }
1717
1818 e .args = []driver.Value {5 , "str" }
1919
20- against = []driver. Value { int64 (5 )}
20+ against = []namedValue {{ Value : int64 (5 ), Ordinal : 1 } }
2121 if err := e .argsMatches (against ); err == nil {
2222 t .Error ("arguments should not match, since the size is not the same" )
2323 }
2424
25- against = []driver.Value {int64 (3 ), "str" }
25+ against = []namedValue {
26+ {Value : int64 (3 ), Ordinal : 1 },
27+ {Value : "str" , Ordinal : 2 },
28+ }
2629 if err := e .argsMatches (against ); err == nil {
2730 t .Error ("arguments should not match, since the first argument (int value) is different" )
2831 }
2932
30- against = []driver.Value {int64 (5 ), "st" }
33+ against = []namedValue {
34+ {Value : int64 (5 ), Ordinal : 1 },
35+ {Value : "st" , Ordinal : 2 },
36+ }
3137 if err := e .argsMatches (against ); err == nil {
3238 t .Error ("arguments should not match, since the second argument (string value) is different" )
3339 }
3440
35- against = []driver.Value {int64 (5 ), "str" }
41+ against = []namedValue {
42+ {Value : int64 (5 ), Ordinal : 1 },
43+ {Value : "str" , Ordinal : 2 },
44+ }
3645 if err := e .argsMatches (against ); err != nil {
3746 t .Errorf ("arguments should match, but it did not: %s" , err )
3847 }
@@ -41,7 +50,10 @@ func TestQueryExpectationArgComparison(t *testing.T) {
4150 tm , _ := time .Parse (longForm , "Feb 3, 2013 at 7:54pm (PST)" )
4251 e .args = []driver.Value {5 , tm }
4352
44- against = []driver.Value {int64 (5 ), tm }
53+ against = []namedValue {
54+ {Value : int64 (5 ), Ordinal : 1 },
55+ {Value : tm , Ordinal : 2 },
56+ }
4557 if err := e .argsMatches (against ); err != nil {
4658 t .Error ("arguments should match, but it did not" )
4759 }
@@ -52,29 +64,95 @@ func TestQueryExpectationArgComparison(t *testing.T) {
5264 }
5365}
5466
67+ func TestQueryExpectationNamedArgComparison (t * testing.T ) {
68+ e := & queryBasedExpectation {}
69+ against := []namedValue {{Value : int64 (5 ), Name : "id" }}
70+ if err := e .argsMatches (against ); err != nil {
71+ t .Errorf ("arguments should match, since the no expectation was set, but got err: %s" , err )
72+ }
73+
74+ e .args = []driver.Value {
75+ namedValue {Name : "id" , Value : int64 (5 )},
76+ namedValue {Name : "s" , Value : "str" },
77+ }
78+
79+ if err := e .argsMatches (against ); err == nil {
80+ t .Error ("arguments should not match, since the size is not the same" )
81+ }
82+
83+ against = []namedValue {
84+ {Value : int64 (5 ), Name : "id" },
85+ {Value : "str" , Name : "s" },
86+ }
87+
88+ if err := e .argsMatches (against ); err != nil {
89+ t .Errorf ("arguments should have matched, but it did not: %v" , err )
90+ }
91+
92+ against = []namedValue {
93+ {Value : int64 (5 ), Name : "id" },
94+ {Value : "str" , Name : "username" },
95+ }
96+
97+ if err := e .argsMatches (against ); err == nil {
98+ t .Error ("arguments matched, but it should have not due to Name" )
99+ }
100+
101+ e .args = []driver.Value {
102+ namedValue {Ordinal : 1 , Value : int64 (5 )},
103+ namedValue {Ordinal : 2 , Value : "str" },
104+ }
105+
106+ against = []namedValue {
107+ {Value : int64 (5 ), Ordinal : 0 },
108+ {Value : "str" , Ordinal : 1 },
109+ }
110+
111+ if err := e .argsMatches (against ); err == nil {
112+ t .Error ("arguments matched, but it should have not due to wrong Ordinal position" )
113+ }
114+
115+ against = []namedValue {
116+ {Value : int64 (5 ), Ordinal : 1 },
117+ {Value : "str" , Ordinal : 2 },
118+ }
119+
120+ if err := e .argsMatches (against ); err != nil {
121+ t .Errorf ("arguments should have matched, but it did not: %v" , err )
122+ }
123+ }
124+
55125func TestQueryExpectationArgComparisonBool (t * testing.T ) {
56126 var e * queryBasedExpectation
57127
58128 e = & queryBasedExpectation {args : []driver.Value {true }}
59- against := []driver.Value {true }
129+ against := []namedValue {
130+ {Value : true , Ordinal : 1 },
131+ }
60132 if err := e .argsMatches (against ); err != nil {
61133 t .Error ("arguments should match, since arguments are the same" )
62134 }
63135
64136 e = & queryBasedExpectation {args : []driver.Value {false }}
65- against = []driver.Value {false }
137+ against = []namedValue {
138+ {Value : false , Ordinal : 1 },
139+ }
66140 if err := e .argsMatches (against ); err != nil {
67141 t .Error ("arguments should match, since argument are the same" )
68142 }
69143
70144 e = & queryBasedExpectation {args : []driver.Value {true }}
71- against = []driver.Value {false }
145+ against = []namedValue {
146+ {Value : false , Ordinal : 1 },
147+ }
72148 if err := e .argsMatches (against ); err == nil {
73149 t .Error ("arguments should not match, since argument is different" )
74150 }
75151
76152 e = & queryBasedExpectation {args : []driver.Value {false }}
77- against = []driver.Value {true }
153+ against = []namedValue {
154+ {Value : true , Ordinal : 1 },
155+ }
78156 if err := e .argsMatches (against ); err == nil {
79157 t .Error ("arguments should not match, since argument is different" )
80158 }
@@ -117,7 +195,7 @@ func TestBuildQuery(t *testing.T) {
117195 name = 'John'
118196 and
119197 address = 'Jakarta'
120-
198+
121199 `
122200
123201 mock .ExpectQuery (query )
0 commit comments