Skip to content

Commit

Permalink
moved prepare unit test environment into separate method to be used a…
Browse files Browse the repository at this point in the history
…cross unit tests

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
  • Loading branch information
daviian committed Sep 20, 2017
1 parent 8df0167 commit c64ea0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions models/action_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package models

import (
"os"
"path"
"strings"
"testing"

"code.gitea.io/git"
"code.gitea.io/gitea/modules/setting"

"github.com/Unknwon/com"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -299,9 +297,7 @@ func TestCommitRepoAction(t *testing.T) {
}

for _, s := range samples {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
assert.NoError(t, com.CopyDir("../integrations/gitea-repositories-meta", setting.RepoRootPath))
prepareTestEnv(t)

user := AssertExistsAndLoadBean(t, &User{ID: s.userID}).(*User)
repo := AssertExistsAndLoadBean(t, &Repository{ID: s.repositoryID, OwnerID: user.ID}).(*Repository)
Expand Down
10 changes: 10 additions & 0 deletions models/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
package models

import (
"os"
"testing"

"code.gitea.io/gitea/modules/setting"

"github.com/Unknwon/com"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -38,6 +42,12 @@ func PrepareTestDatabase() error {
return LoadFixtures()
}

func prepareTestEnv(t testing.TB) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
assert.NoError(t, com.CopyDir("../integrations/gitea-repositories-meta", setting.RepoRootPath))
}

type testCond struct {
query interface{}
args []interface{}
Expand Down

0 comments on commit c64ea0c

Please sign in to comment.