Move fixture generation to contrib and add test (#10277)

* Add fixture gen tool and fix "access" test

* Close file before exiting

* Add missing repo_unit for repo id: 5

* Fix count on TestAPIOrgRepos

* Generate access fixture from contrib and add test

* Remove old access fixture generation

* Fix lint

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
guillep2k 2020-02-15 05:59:43 -03:00 committed by GitHub
parent 62a1322cf9
commit 7e920703f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 163 additions and 56 deletions

View file

@ -28,7 +28,10 @@ import (
const NonexistentID = int64(math.MaxInt64)
// giteaRoot a path to the gitea root
var giteaRoot string
var (
giteaRoot string
fixturesDir string
)
func fatalTestError(fmtStr string, args ...interface{}) {
fmt.Fprintf(os.Stderr, fmtStr, args...)
@ -40,8 +43,8 @@ func fatalTestError(fmtStr string, args ...interface{}) {
func MainTest(m *testing.M, pathToGiteaRoot string) {
var err error
giteaRoot = pathToGiteaRoot
fixturesDir := filepath.Join(pathToGiteaRoot, "models", "fixtures")
if err = createTestEngine(fixturesDir); err != nil {
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
if err = CreateTestEngine(fixturesDir); err != nil {
fatalTestError("Error creating test engine: %v\n", err)
}
@ -82,7 +85,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
os.Exit(exitStatus)
}
func createTestEngine(fixturesDir string) error {
// CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
func CreateTestEngine(fixturesDir string) error {
var err error
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
if err != nil {