mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-06-04 23:17:28 +02:00
asserts ordinal argument position, fixes expected query error message
This commit is contained in:
parent
53b2cd1534
commit
a00b6aa80e
@ -167,14 +167,7 @@ func (e *ExpectedQuery) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if e.rows != nil {
|
if e.rows != nil {
|
||||||
msg += "\n - should return rows:\n"
|
msg += fmt.Sprintf("\n - %s", e.rows)
|
||||||
rs, _ := e.rows.(*rowSets)
|
|
||||||
for _, set := range rs.sets {
|
|
||||||
for i, row := range set.rows {
|
|
||||||
msg += fmt.Sprintf(" %d - %+v\n", i, row)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msg = strings.TrimSpace(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.err != nil {
|
if e.err != nil {
|
||||||
|
@ -32,7 +32,6 @@ func (e *queryBasedExpectation) argsMatches(args []namedValue) error {
|
|||||||
// custom argument matcher
|
// custom argument matcher
|
||||||
matcher, ok := e.args[k].(Argument)
|
matcher, ok := e.args[k].(Argument)
|
||||||
if ok {
|
if ok {
|
||||||
// @TODO: does it make sense to pass value instead of named value?
|
|
||||||
if !matcher.Match(v.Value) {
|
if !matcher.Match(v.Value) {
|
||||||
return fmt.Errorf("matcher %T could not match %d argument %T - %+v", matcher, k, args[k], args[k])
|
return fmt.Errorf("matcher %T could not match %d argument %T - %+v", matcher, k, args[k], args[k])
|
||||||
}
|
}
|
||||||
@ -45,6 +44,8 @@ func (e *queryBasedExpectation) argsMatches(args []namedValue) error {
|
|||||||
if v.Name != named.Name {
|
if v.Name != named.Name {
|
||||||
return fmt.Errorf("named argument %d: name: \"%s\" does not match expected: \"%s\"", k, v.Name, named.Name)
|
return fmt.Errorf("named argument %d: name: \"%s\" does not match expected: \"%s\"", k, v.Name, named.Name)
|
||||||
}
|
}
|
||||||
|
} else if k+1 != v.Ordinal {
|
||||||
|
return fmt.Errorf("argument %d: ordinal position: %d does not match expected: %d", k, k+1, v.Ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to driver converter
|
// convert to driver converter
|
||||||
|
19
rows.go
19
rows.go
@ -3,6 +3,7 @@ package sqlmock
|
|||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -46,6 +47,24 @@ func (rs *rowSets) Next(dest []driver.Value) error {
|
|||||||
return r.nextErr[r.pos-1]
|
return r.nextErr[r.pos-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transforms to debuggable printable string
|
||||||
|
func (rs *rowSets) String() string {
|
||||||
|
msg := "should return rows:\n"
|
||||||
|
if len(rs.sets) == 1 {
|
||||||
|
for n, row := range rs.sets[0].rows {
|
||||||
|
msg += fmt.Sprintf(" row %d - %+v\n", n, row)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(msg)
|
||||||
|
}
|
||||||
|
for i, set := range rs.sets {
|
||||||
|
msg += fmt.Sprintf(" result set: %d\n", i)
|
||||||
|
for n, row := range set.rows {
|
||||||
|
msg += fmt.Sprintf(" row %d - %+v\n", n, row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(msg)
|
||||||
|
}
|
||||||
|
|
||||||
// Rows is a mocked collection of rows to
|
// Rows is a mocked collection of rows to
|
||||||
// return for Query result
|
// return for Query result
|
||||||
type Rows struct {
|
type Rows struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user