You've already forked go-sqlmock
mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-06-14 23:55:00 +02:00
improves error messages, closes #77
This commit is contained in:
30
sqlmock.go
30
sqlmock.go
@ -247,7 +247,7 @@ func (c *sqlmock) exec(query string, args []namedValue) (*ExpectedExec, error) {
|
||||
break
|
||||
}
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to exec query '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
return nil, fmt.Errorf("call to ExecQuery '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
}
|
||||
if exec, ok := next.(*ExpectedExec); ok {
|
||||
if err := exec.attemptMatch(query, args); err == nil {
|
||||
@ -258,7 +258,7 @@ func (c *sqlmock) exec(query string, args []namedValue) (*ExpectedExec, error) {
|
||||
next.Unlock()
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to exec '%s' query with args %+v was not expected"
|
||||
msg := "call to ExecQuery '%s' with args %+v was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
@ -267,11 +267,11 @@ func (c *sqlmock) exec(query string, args []namedValue) (*ExpectedExec, error) {
|
||||
defer expected.Unlock()
|
||||
|
||||
if !expected.queryMatches(query) {
|
||||
return nil, fmt.Errorf("exec query '%s', does not match regex '%s'", query, expected.sqlRegex.String())
|
||||
return nil, fmt.Errorf("ExecQuery '%s', does not match regex '%s'", query, expected.sqlRegex.String())
|
||||
}
|
||||
|
||||
if err := expected.argsMatches(args); err != nil {
|
||||
return nil, fmt.Errorf("exec query '%s', arguments do not match: %s", query, err)
|
||||
return nil, fmt.Errorf("ExecQuery '%s', arguments do not match: %s", query, err)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
@ -280,7 +280,7 @@ func (c *sqlmock) exec(query string, args []namedValue) (*ExpectedExec, error) {
|
||||
}
|
||||
|
||||
if expected.result == nil {
|
||||
return nil, fmt.Errorf("exec query '%s' with args %+v, must return a database/sql/driver.result, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
return nil, fmt.Errorf("ExecQuery '%s' with args %+v, must return a database/sql/driver.Result, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
}
|
||||
|
||||
return expected, nil
|
||||
@ -337,7 +337,7 @@ func (c *sqlmock) prepare(query string) (*ExpectedPrepare, error) {
|
||||
}
|
||||
defer expected.Unlock()
|
||||
if !expected.sqlRegex.MatchString(query) {
|
||||
return nil, fmt.Errorf("query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||
return nil, fmt.Errorf("Prepare query string '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
@ -394,7 +394,7 @@ func (c *sqlmock) query(query string, args []namedValue) (*ExpectedQuery, error)
|
||||
break
|
||||
}
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to query '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
return nil, fmt.Errorf("call to Query '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
}
|
||||
if qr, ok := next.(*ExpectedQuery); ok {
|
||||
if err := qr.attemptMatch(query, args); err == nil {
|
||||
@ -406,7 +406,7 @@ func (c *sqlmock) query(query string, args []namedValue) (*ExpectedQuery, error)
|
||||
}
|
||||
|
||||
if expected == nil {
|
||||
msg := "call to query '%s' with args %+v was not expected"
|
||||
msg := "call to Query '%s' with args %+v was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
@ -416,11 +416,11 @@ func (c *sqlmock) query(query string, args []namedValue) (*ExpectedQuery, error)
|
||||
defer expected.Unlock()
|
||||
|
||||
if !expected.queryMatches(query) {
|
||||
return nil, fmt.Errorf("query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||
return nil, fmt.Errorf("Query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||
}
|
||||
|
||||
if err := expected.argsMatches(args); err != nil {
|
||||
return nil, fmt.Errorf("exec query '%s', arguments do not match: %s", query, err)
|
||||
return nil, fmt.Errorf("Query '%s', arguments do not match: %s", query, err)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
@ -429,7 +429,7 @@ func (c *sqlmock) query(query string, args []namedValue) (*ExpectedQuery, error)
|
||||
}
|
||||
|
||||
if expected.rows == nil {
|
||||
return nil, fmt.Errorf("query '%s' with args %+v, must return a database/sql/driver.rows, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
return nil, fmt.Errorf("Query '%s' with args %+v, must return a database/sql/driver.Rows, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
}
|
||||
return expected, nil
|
||||
}
|
||||
@ -473,11 +473,11 @@ func (c *sqlmock) Commit() error {
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return fmt.Errorf("call to commit transaction, was not expected, next expectation is: %s", next)
|
||||
return fmt.Errorf("call to Commit transaction, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to commit transaction was not expected"
|
||||
msg := "call to Commit transaction was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
@ -508,11 +508,11 @@ func (c *sqlmock) Rollback() error {
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return fmt.Errorf("call to rollback transaction, was not expected, next expectation is: %s", next)
|
||||
return fmt.Errorf("call to Rollback transaction, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to rollback transaction was not expected"
|
||||
msg := "call to Rollback transaction was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
|
Reference in New Issue
Block a user