func TestTableStructureIn(t *testing.T) { want := map[string]bool{ "catalog_category_anc_categs_index_idx": true, "catalog_category_anc_categs_index_tmp": true, "catalog_category_anc_products_index_idx": false, } for i := csdb.Index(0); tableMap.Next(i); i++ { table, err := tableMap.Structure(i) if err != nil { t.Error(err) } have := table.In("path") assert.EqualValues(t, want[table.Name], have, "Table %s", table.Name) } want2 := map[string]bool{ "catalog_category_anc_categs_index_idx": true, "catalog_category_anc_categs_index_tmp": true, "catalog_category_anc_products_index_idx": true, } for i := csdb.Index(0); i < tableMap.Len(); i++ { table, err := tableMap.Structure(i) if err != nil { t.Error(err) } have := table.In("category_id") assert.EqualValues(t, want2[table.Name], have, "Table %s", table.Name) } }
func TestNewTableManagerAppend(t *testing.T) { defer func() { if r := recover(); r != nil { assert.Contains(t, r.(string), "Table pointer cannot be nil for Index") } }() tm0 := csdb.NewTableManager() tm0.Append(csdb.Index(0), nil) assert.NotNil(t, tm0) assert.Equal(t, tm0.Len(), csdb.Index(0)) }
func TestNewTableManagerPanic(t *testing.T) { defer func() { if r := recover(); r != nil { assert.Contains(t, r.(string), csdb.ErrManagerIncorrectValue.Error()) } }() tm0 := csdb.NewTableManager( csdb.AddTableByName(csdb.Index(0), ""), ) assert.NotNil(t, tm0) assert.Equal(t, tm0.Len(), csdb.Index(0)) }
func TestNewTableManager(t *testing.T) { assert.Equal(t, csdb.NewTableManager().Len(), csdb.Index(0)) const ( TableIndexStore csdb.Index = iota // Table: store TableIndexGroup // Table: store_group TableIndexWebsite // Table: store_website TableIndexZZZ // the maximum index, which is not available. ) tm1 := csdb.NewTableManager( csdb.AddTableByName(TableIndexStore, "store"), csdb.AddTableByName(TableIndexGroup, "store_group"), csdb.AddTableByName(TableIndexWebsite, "store_website"), ) assert.Equal(t, tm1.Len(), csdb.Index(3)) }
func TestTableStructureTableAliasQuote(t *testing.T) { want := map[string]string{ "catalog_category_anc_categs_index_idx": "`catalog_category_anc_categs_index_idx` AS `alias`", "catalog_category_anc_categs_index_tmp": "`catalog_category_anc_categs_index_tmp` AS `alias`", "catalog_category_anc_products_index_idx": "`catalog_category_anc_products_index_idx` AS `alias`", } for i := csdb.Index(0); tableMap.Next(i); i++ { table, err := tableMap.Structure(i) if err != nil { t.Error(err) } have := table.TableAliasQuote("alias") assert.EqualValues(t, want[table.Name], have, "Table %s", table.Name) } }
func TestTableStructureAllColumnAliasQuote(t *testing.T) { want := map[string][]string{ "catalog_category_anc_categs_index_idx": []string{"`alias`.`category_id`", "`alias`.`path`"}, "catalog_category_anc_categs_index_tmp": []string{"`alias`.`category_id`", "`alias`.`path`"}, "catalog_category_anc_products_index_idx": []string{"`alias`.`category_id`", "`alias`.`product_id`", "`alias`.`position`"}, } for i := csdb.Index(0); tableMap.Next(i); i++ { table, err := tableMap.Structure(i) if err != nil { t.Error(err) } have := table.AllColumnAliasQuote("alias") assert.EqualValues(t, want[table.Name], have, "Table %s", table.Name) } }
func TestNewTableManagerInit(t *testing.T) { dbc := csdb.MustConnectTest() defer dbc.Close() i := csdb.Index(4711) tm0 := csdb.NewTableManager(csdb.AddTableByName(i, "admin_user")) assert.EqualError(t, tm0.Init(dbc.NewSession(), true), csdb.ErrManagerInitReload.Error()) err := tm0.Init(dbc.NewSession()) assert.NoError(t, err) table, err2 := tm0.Structure(i) assert.NoError(t, err2) assert.Equal(t, 1, table.CountPK) assert.Equal(t, 1, table.CountUnique) assert.True(t, len(table.Columns.FieldNames()) >= 15) assert.Nil(t, tm0.Init(dbc.NewSession())) }