You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_fixtures.go 821 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "gopkg.in/testfixtures.v2"
  7. )
  8. var fixtures *testfixtures.Context
  9. // InitFixtures initialize test fixtures for a test database
  10. func InitFixtures(helper testfixtures.Helper, dir string) (err error) {
  11. testfixtures.SkipDatabaseNameCheck(true)
  12. fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir)
  13. return err
  14. }
  15. // LoadFixtures load fixtures for a test database
  16. func LoadFixtures() error {
  17. var err error
  18. // Database transaction conflicts could occur and result in ROLLBACK
  19. // As a simple workaround, we just retry 5 times.
  20. for i := 0; i < 5; i++ {
  21. err = fixtures.Load()
  22. if err == nil {
  23. break
  24. }
  25. }
  26. return err
  27. }