mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: fix unit tests failing on repeated runs (#39915)
`go test -count=2` failed in 12 packages because tests leaked state into later runs. - Reset SQLite sequences after each fixture load, like PostgreSQL already does - Prepare the database in tests that relied on earlier tests doing it - Restore mutated globals with `test.MockVariableValue`
This commit is contained in:
1 parent
ef55965d98
commit
98c613d943
20 files changed
+124
-66
No files matched your search
@@ -169,10 +169,21 @@ func LoadFixtures() error {
|
||||
return err
|
||||
}
|
||||
// Now if we're running postgres we need to tell it to update the sequences
|
||||
if GetXORMEngine().Dialect().URI().DBType == schemas.POSTGRES {
|
||||
switch GetXORMEngine().Dialect().URI().DBType {
|
||||
case schemas.POSTGRES:
|
||||
if err := loadFixtureResetSeqPgsql(GetXORMEngine()); err != nil {
|
||||
return err
|
||||
}
|
||||
case schemas.SQLITE:
|
||||
hasSequence, err := GetXORMEngine().IsTableExist("sqlite_sequence") // only exists once an AUTOINCREMENT table was created
|
||||
if err != nil {
|
||||
return fmt.Errorf("LoadFixtures: %w", err)
|
||||
}
|
||||
if hasSequence {
|
||||
if _, err := GetXORMEngine().DB().DB.Exec("DELETE FROM sqlite_sequence"); err != nil {
|
||||
return fmt.Errorf("LoadFixtures: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user