Fix various mysql data type conversions (#3554)

This commit is contained in:
Mike Danko
2017-12-12 16:22:11 -05:00
committed by Daniel Nelson
parent 825d338386
commit 60c39ced69
2 changed files with 54 additions and 288 deletions

View File

@@ -127,26 +127,29 @@ func TestMysqlDNSAddTimeout(t *testing.T) {
}
}
}
func TestParseValue(t *testing.T) {
testCases := []struct {
rawByte sql.RawBytes
value float64
output interface{}
boolValue bool
}{
{sql.RawBytes("Yes"), 1, true},
{sql.RawBytes("No"), 0, false},
{sql.RawBytes("123"), int64(123), true},
{sql.RawBytes("abc"), "abc", true},
{sql.RawBytes("10.1"), 10.1, true},
{sql.RawBytes("ON"), 1, true},
{sql.RawBytes("OFF"), 0, false},
{sql.RawBytes("ABC"), 0, false},
{sql.RawBytes("OFF"), 0, true},
{sql.RawBytes("NO"), 0, true},
{sql.RawBytes("YES"), 1, true},
{sql.RawBytes("No"), 0, true},
{sql.RawBytes("Yes"), 1, true},
{sql.RawBytes(""), nil, false},
}
for _, cases := range testCases {
if value, ok := parseValue(cases.rawByte); value != cases.value && ok != cases.boolValue {
t.Errorf("want %d with %t, got %d with %t", int(cases.value), cases.boolValue, int(value), ok)
if got, ok := parseValue(cases.rawByte); got != cases.output && ok != cases.boolValue {
t.Errorf("for %s wanted %t, got %t", string(cases.rawByte), cases.output, got)
}
}
}
func TestNewNamespace(t *testing.T) {
testCases := []struct {
words []string