1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-01-10 00:28:42 +02:00
go-sqlmock/expectations_test.go

60 lines
1.5 KiB
Go
Raw Normal View History

2014-02-05 17:21:07 +03:00
package sqlmock
import (
2014-05-29 16:43:37 +03:00
"database/sql/driver"
"testing"
"time"
2014-02-05 17:21:07 +03:00
)
2014-05-29 16:43:37 +03:00
type matcher struct {
}
func (m matcher) Match(driver.Value) bool {
return true
}
2014-02-05 17:21:07 +03:00
func TestQueryExpectationArgComparison(t *testing.T) {
2014-05-29 16:43:37 +03:00
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")
}
against = []driver.Value{5, matcher{}}
if !e.argsMatches(against) {
t.Error("arguments should match, but it did not")
}
2014-02-05 17:21:07 +03:00
}