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.

main_test.go 1.3 kB

8 years ago
8 years ago
8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package models
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/go-xorm/core"
  9. "github.com/go-xorm/xorm"
  10. _ "github.com/mattn/go-sqlite3" // for the test engine
  11. "github.com/stretchr/testify/assert"
  12. "gopkg.in/testfixtures.v2"
  13. )
  14. // TestFixturesAreConsistent assert that test fixtures are consistent
  15. func TestFixturesAreConsistent(t *testing.T) {
  16. assert.NoError(t, PrepareTestDatabase())
  17. CheckConsistencyForAll(t)
  18. }
  19. // CreateTestEngine create an xorm engine for testing
  20. func CreateTestEngine() error {
  21. var err error
  22. x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
  23. if err != nil {
  24. return err
  25. }
  26. x.SetMapper(core.GonicMapper{})
  27. if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
  28. return err
  29. }
  30. return InitFixtures(&testfixtures.SQLite{}, "fixtures/")
  31. }
  32. func TestMain(m *testing.M) {
  33. if err := CreateTestEngine(); err != nil {
  34. fmt.Printf("Error creating test engine: %v\n", err)
  35. os.Exit(1)
  36. }
  37. setting.AppURL = "https://try.gitea.io/"
  38. setting.RunUser = "runuser"
  39. setting.SSH.Port = 3000
  40. setting.SSH.Domain = "try.gitea.io"
  41. setting.RepoRootPath = filepath.Join(os.TempDir(), "repos")
  42. setting.AppDataPath = filepath.Join(os.TempDir(), "appdata")
  43. os.Exit(m.Run())
  44. }