aboutsummaryrefslogtreecommitdiffstats
path: root/models/setup_for_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-01-07 22:10:53 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-08 11:10:53 +0800
commit6072b032918006824f260e79f96372dd94fbb17f (patch)
tree16e9ee4c0f0550ec55dd2463496649d44e2dfe99 /models/setup_for_test.go
parent8422ab542c69592b4629188d4460ca560307465b (diff)
downloadgitea-6072b032918006824f260e79f96372dd94fbb17f.tar.gz
gitea-6072b032918006824f260e79f96372dd94fbb17f.zip
Unit tests for models/access.go (#606)
Diffstat (limited to 'models/setup_for_test.go')
-rw-r--r--models/setup_for_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/models/setup_for_test.go b/models/setup_for_test.go
index b585a7490e..cf88397c26 100644
--- a/models/setup_for_test.go
+++ b/models/setup_for_test.go
@@ -12,6 +12,7 @@ import (
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" // for the test engine
+ "github.com/stretchr/testify/assert"
"gopkg.in/testfixtures.v2"
)
@@ -45,3 +46,17 @@ func CreateTestEngine() error {
func PrepareTestDatabase() error {
return fixtures.Load()
}
+
+// LoadFixture load a test fixture from the test database, failing if fixture
+// does not exist
+func LoadTestFixture(t *testing.T, fixture interface{}, conditions... interface{}) {
+ sess := x.NewSession()
+ defer sess.Close()
+
+ for _, cond := range conditions {
+ sess = sess.Where(cond)
+ }
+ has, err := sess.Get(fixture)
+ assert.NoError(t, err)
+ assert.True(t, has)
+}