gh-ost/go/sql/types_test.go

45 lines
1.0 KiB
Go
Raw Normal View History

2016-04-11 17:06:47 +00:00
/*
Copyright 2016 GitHub Inc.
2016-05-16 09:09:17 +00:00
See https://github.com/github/gh-ost/blob/master/LICENSE
2016-04-11 17:06:47 +00:00
*/
package sql
import (
"testing"
"reflect"
"github.com/openark/golib/log"
test "github.com/openark/golib/tests"
2016-04-11 17:06:47 +00:00
)
func init() {
log.SetLevel(log.ERROR)
}
func TestParseColumnList(t *testing.T) {
names := "id,category,max_len"
columnList := ParseColumnList(names)
test.S(t).ExpectEquals(columnList.Len(), 3)
test.S(t).ExpectTrue(reflect.DeepEqual(columnList.Names(), []string{"id", "category", "max_len"}))
2016-04-11 17:06:47 +00:00
test.S(t).ExpectEquals(columnList.Ordinals["id"], 0)
test.S(t).ExpectEquals(columnList.Ordinals["category"], 1)
test.S(t).ExpectEquals(columnList.Ordinals["max_len"], 2)
}
2016-10-13 11:13:00 +00:00
func TestGetColumn(t *testing.T) {
names := "id,category,max_len"
columnList := ParseColumnList(names)
{
column := columnList.GetColumn("category")
test.S(t).ExpectTrue(column != nil)
test.S(t).ExpectEquals(column.Name, "category")
}
{
column := columnList.GetColumn("no_such_column")
test.S(t).ExpectTrue(column == nil)
}
}