Unit tests for models/access.go (#606)

This commit is contained in:
Ethan Koenig 2017-01-07 22:10:53 -05:00 committed by Lunny Xiao
parent 8422ab542c
commit 6072b03291
10 changed files with 258 additions and 0 deletions

View file

@ -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)
}