Skip to content

Instantly share code, notes, and snippets.

@mackee
Last active August 29, 2015 14:17
Show Gist options
  • Save mackee/36c208f6909eefd0a7e4 to your computer and use it in GitHub Desktop.
Save mackee/36c208f6909eefd0a7e4 to your computer and use it in GitHub Desktop.
package mizar
import (
"testing"
)
type Table1 struct {
Id DBInteger `db:"id"`
Name DBVarchar `db:"name"`
Description DBVarchar
}
func (t1 Table1) TableName() string {
return "t1"
}
func TestSearchFullColumn(t *testing.T) {
mi := &Mizar{}
rs, err := mi.Search(
Table1{
Id: NewDBInteger(1),
Name: NewDBVarchar("hogehoge"),
Description: NewDBVarchar("barbar"),
},
)
if err != nil {
t.Error("unexpected Search() error:", err)
}
q, args, err := rs.ToSql()
if err != nil {
t.Error("unexpected ToSql() error:", err)
}
if q != "SELECT * FROM t1 WHERE id = ? AND name = ?" {
t.Error("unexpected query:", q)
}
if args[0].(int64) != 1 {
t.Error("unexpected args[0]:", args[0])
}
if args[1].(string) != "hogehoge" {
t.Error("unexpected args[1]:", args[1])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment