Commit 3d6092ae authored by gwenn's avatar gwenn

Use Logf in trace tests.

parent b1be6529
......@@ -11,38 +11,70 @@ func init() {
}
func trace(d interface{}, sql string) {
//fmt.Printf("%s: %s\n", d, sql)
if t, ok := d.(*testing.T); ok {
t.Logf("TRACE: %s\n", sql)
} else {
fmt.Printf("%s: %s\n", d, sql)
}
}
func authorizer(d interface{}, action Action, arg1, arg2, dbName, triggerName string) Auth {
//fmt.Printf("%s: %d, %s, %s, %s, %s\n", d, action, arg1, arg2, dbName, triggerName)
if t, ok := d.(*testing.T); ok {
t.Logf("AUTH: %d, %s, %s, %s, %s\n", action, arg1, arg2, dbName, triggerName)
} else {
fmt.Printf("%s: %d, %s, %s, %s, %s\n", d, action, arg1, arg2, dbName, triggerName)
}
return AUTH_OK
}
func profile(d interface{}, sql string, nanoseconds uint64) {
//fmt.Printf("%s: %s = %d µs\n", d, sql, nanoseconds/1e3)
if t, ok := d.(*testing.T); ok {
t.Logf("PROFILE: %s = %d µs\n", sql, nanoseconds/1e3)
} else {
fmt.Printf("%s: %s = %d µs\n", d, sql, nanoseconds/1e3)
}
}
func progressHandler(d interface{}) bool {
//fmt.Print("+")
if t, ok := d.(*testing.T); ok {
t.Log("+")
} else {
fmt.Print("+")
}
return false
}
func commitHook(d interface{}) bool {
if t, ok := d.(*testing.T); ok {
t.Log("CMT")
} else {
fmt.Printf("%s\n", d)
}
return false
}
func rollbackHook(d interface{}) {
if t, ok := d.(*testing.T); ok {
t.Log("RBK")
} else {
fmt.Printf("%s\n", d)
}
}
func updateHook(d interface{}, a Action, dbName, tableName string, rowId int64) {
if t, ok := d.(*testing.T); ok {
t.Logf("UPD: %d, %s.%s.%d\n", a, dbName, tableName, rowId)
} else {
fmt.Printf("%s: %d, %s.%s.%d\n", d, a, dbName, tableName, rowId)
}
}
func log(d interface{}, err error, msg string) {
if t, ok := d.(*testing.T); ok {
t.Logf("%s: %s\n", err, msg)
} else {
fmt.Printf("%s: %s, %s\n", d, err, msg)
}
}
func TestNoTrace(t *testing.T) {
......@@ -63,14 +95,14 @@ func TestTrace(t *testing.T) {
db, err := Open("")
checkNoError(t, err, "couldn't open database: %s")
defer db.Close()
db.Trace(trace, "TRACE")
err = db.SetAuthorizer(authorizer, "AUTH")
db.Trace(trace, t)
err = db.SetAuthorizer(authorizer, t)
checkNoError(t, err, "couldn't set an authorizer")
db.Profile(profile, "PROFILE")
db.ProgressHandler(progressHandler, 1, nil /*20*/)
db.CommitHook(commitHook, "CMT")
db.RollbackHook(rollbackHook, "RBK")
db.UpdateHook(updateHook, "UPD")
db.Profile(profile, t)
db.ProgressHandler(progressHandler, 1, t)
db.CommitHook(commitHook, t)
db.RollbackHook(rollbackHook, t)
db.UpdateHook(updateHook, t)
db.Exists("SELECT 1 WHERE 1 = ?", 1)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment