func testNoCacheDomain(engine *xorm.Engine, t *testing.T) { err := engine.CreateTables(&NoCacheDomain{}) if err != nil { t.Error(err) panic(err) } table := engine.TableInfo(&NoCacheDomain{}) if table.Cacher != nil { err = fmt.Errorf("table cache exist") t.Error(err) panic(err) } }
func testCompositeKey(engine *xorm.Engine, t *testing.T) { err := engine.DropTables(&CompositeKey{}) if err != nil { t.Error(err) panic(err) } err = engine.CreateTables(&CompositeKey{}) if err != nil { t.Error(err) panic(err) } cnt, err := engine.Insert(&CompositeKey{11, 22, ""}) if err != nil { t.Error(err) } else if cnt != 1 { t.Error(errors.New("failed to insert CompositeKey{11, 22}")) } cnt, err = engine.Insert(&CompositeKey{11, 22, ""}) if err == nil || cnt == 1 { t.Error(errors.New("inserted CompositeKey{11, 22}")) } var compositeKeyVal CompositeKey has, err := engine.Id(core.PK{11, 22}).Get(&compositeKeyVal) if err != nil { t.Error(err) } else if !has { t.Error(errors.New("can't get CompositeKey{11, 22}")) } var compositeKeyVal2 CompositeKey // test passing PK ptr, this test seem failed withCache has, err = engine.Id(&core.PK{11, 22}).Get(&compositeKeyVal2) if err != nil { t.Error(err) } else if !has { t.Error(errors.New("can't get CompositeKey{11, 22}")) } if compositeKeyVal != compositeKeyVal2 { t.Error(errors.New("should be equal")) } var cps = make([]CompositeKey, 0) err = engine.Find(&cps) if err != nil { t.Error(err) } if len(cps) != 1 { t.Error(errors.New("should has one record")) } if cps[0] != compositeKeyVal { t.Error(errors.New("should be equal")) } cnt, err = engine.Insert(&CompositeKey{22, 22, ""}) if err != nil { t.Error(err) } else if cnt != 1 { t.Error(errors.New("failed to insert CompositeKey{22, 22}")) } if engine.Cacher != nil { engine.Cacher.ClearBeans(engine.TableInfo(compositeKeyVal).Name) } cps = make([]CompositeKey, 0) err = engine.Find(&cps) if err != nil { t.Error(err) } if len(cps) != 2 { t.Error(errors.New("should has two record")) } if cps[0] != compositeKeyVal { t.Error(errors.New("should be equeal")) } compositeKeyVal = CompositeKey{UpdateStr: "test1"} cnt, err = engine.Id(core.PK{11, 22}).Update(&compositeKeyVal) if err != nil { t.Error(err) } else if cnt != 1 { t.Error(errors.New("can't update CompositeKey{11, 22}")) } cnt, err = engine.Id(core.PK{11, 22}).Delete(&CompositeKey{}) if err != nil { t.Error(err) } else if cnt != 1 { t.Error(errors.New("can't delete CompositeKey{11, 22}")) } }