gh-ost/go/logic/inspect_test.go
Tim Vaillancourt 05c7ed5f8f
Add basic test for inspector (#1166)
* Add basic test for inspector

* Add header

* Fix return
2022-09-06 15:23:18 +02:00

32 lines
951 B
Go

/*
Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE
*/
package logic
import (
"testing"
test "github.com/openark/golib/tests"
"github.com/github/gh-ost/go/sql"
)
func TestInspectGetSharedUniqueKeys(t *testing.T) {
origUniqKeys := []*sql.UniqueKey{
{Columns: *sql.NewColumnList([]string{"id", "item_id"})},
{Columns: *sql.NewColumnList([]string{"id", "org_id"})},
}
ghostUniqKeys := []*sql.UniqueKey{
{Columns: *sql.NewColumnList([]string{"id", "item_id"})},
{Columns: *sql.NewColumnList([]string{"id", "org_id"})},
{Columns: *sql.NewColumnList([]string{"item_id", "user_id"})},
}
inspector := &Inspector{}
sharedUniqKeys := inspector.getSharedUniqueKeys(origUniqKeys, ghostUniqKeys)
test.S(t).ExpectEquals(len(sharedUniqKeys), 2)
test.S(t).ExpectEquals(sharedUniqKeys[0].Columns.String(), "id,item_id")
test.S(t).ExpectEquals(sharedUniqKeys[1].Columns.String(), "id,org_id")
}