2
0
Files
pgx/sanitize_test.go
T
2013-05-07 08:19:12 -05:00

38 lines
846 B
Go

package pgx
import (
"testing"
)
func TestQuoteString(t *testing.T) {
conn := getSharedConnection()
if conn.QuoteString("test") != "'test'" {
t.Error("Failed to quote string")
}
if conn.QuoteString("Jack's") != "'Jack''s'" {
t.Error("Failed to quote and escape string with embedded quote")
}
}
func TestSanitizeSql(t *testing.T) {
conn := getSharedConnection()
if conn.SanitizeSql("select $1", "Jack's") != "select 'Jack''s'" {
t.Error("Failed to sanitize string")
}
if conn.SanitizeSql("select $1", 42) != "select 42" {
t.Error("Failed to pass through integer")
}
if conn.SanitizeSql("select $1", 1.23) != "select 1.23" {
t.Error("Failed to pass through float")
}
if conn.SanitizeSql("select $1, $2, $3", "Jack's", 42, 1.23) != "select 'Jack''s', 42, 1.23" {
t.Error("Failed to sanitize multiple params")
}
}