Susumu Yata
null+****@clear*****
Thu Sep 14 14:27:21 JST 2017
Susumu Yata 2017-09-14 14:27:21 +0900 (Thu, 14 Sep 2017) New Revision: 7a032b1e7c8f3d23d91848764dfc9779be525fdb https://github.com/groonga/grnci/commit/7a032b1e7c8f3d23d91848764dfc9779be525fdb Message: Add tests for DB.ColumnRename and DB.TableRename. Ref: #39 Modified files: v2/libgrn/db_test.go Modified: v2/libgrn/db_test.go (+70 -0) =================================================================== --- v2/libgrn/db_test.go 2017-09-14 14:22:29 +0900 (8aaacc4) +++ v2/libgrn/db_test.go 2017-09-14 14:27:21 +0900 (e84e3f2) @@ -165,6 +165,48 @@ func TestDBColumnRemoveInvalidColumn(t *testing.T) { } } +func TestDBColumnRename(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + dump := `table_create Tbl TABLE_NO_KEY +column_create Tbl col COLUMN_SCALAR ShortText` + if _, err := db.Restore(strings.NewReader(dump), nil, true); err != nil { + t.Fatalf("db.Restore failed: %v", err) + } + if err := db.ColumnRename("Tbl.col", "col2"); err != nil { + t.Fatalf("db.ColumnRename failed: %v", err) + } + if ok, _ := db.ObjectExist("Tbl.col"); ok { + t.Fatalf("db.ObjectExist wrongly succeeded") + } + if ok, err := db.ObjectExist("Tbl.col2"); !ok { + t.Fatalf("db.ObjectExist failed: %v", err) + } +} + +func TestDBColumnRenameInvalidTable(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + if err := db.ColumnRename("no_such_table.col", "col2"); err == nil { + t.Fatalf("db.ColumnRename wrongly succeeded.") + } +} + +func TestDBColumnRenameInvalidName(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + dump := `table_create Tbl TABLE_NO_KEY` + if _, err := db.Restore(strings.NewReader(dump), nil, true); err != nil { + t.Fatalf("db.Restore failed: %v", err) + } + if err := db.ColumnRename("Tbl.no_such_column", "col2"); err == nil { + t.Fatalf("db.ColumnRename wrongly succeeded.") + } +} + func TestDBConfigDelete(t *testing.T) { db, dir := makeDB(t) defer removeDB(db, dir) @@ -1092,6 +1134,34 @@ table_create Referrer TABLE_HASH_KEY Referred` } } +func TestDBTableRename(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + dump := `table_create Tbl TABLE_NO_KEY` + if _, err := db.Restore(strings.NewReader(dump), nil, true); err != nil { + t.Fatalf("db.Restore failed: %v", err) + } + if err := db.TableRename("Tbl", "Tbl2"); err != nil { + t.Fatalf("db.TableRename failed: %v", err) + } + if ok, _ := db.ObjectExist("Tbl"); ok { + t.Fatalf("db.ObjectExist wrongly succeeded") + } + if ok, err := db.ObjectExist("Tbl2"); !ok { + t.Fatalf("db.ObjectExist failed: %v", err) + } +} + +func TestDBTableRenameInvalidName(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + if err := db.TableRename("no_such_table", "col2"); err == nil { + t.Fatalf("db.TableRename wrongly succeeded.") + } +} + func TestDBTableTokenize(t *testing.T) { db, dir := makeDB(t) defer removeDB(db, dir) -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170914/306eb69a/attachment-0001.htm