Skip to content

Commit 82f5283

Browse files
committed
Fix compiling without sqlite and gcc
1 parent f33e6ae commit 82f5283

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

models/main_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import (
88

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

11+
"github.com/go-xorm/core"
12+
"github.com/go-xorm/xorm"
13+
_ "github.com/mattn/go-sqlite3" // for the test engine
1114
"github.com/stretchr/testify/assert"
15+
"gopkg.in/testfixtures.v2"
1216
)
1317

1418
// TestFixturesAreConsistent assert that test fixtures are consistent
@@ -17,6 +21,21 @@ func TestFixturesAreConsistent(t *testing.T) {
1721
CheckConsistencyForAll(t)
1822
}
1923

24+
// CreateTestEngine create an xorm engine for testing
25+
func CreateTestEngine() error {
26+
var err error
27+
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
28+
if err != nil {
29+
return err
30+
}
31+
x.SetMapper(core.GonicMapper{})
32+
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
33+
return err
34+
}
35+
36+
return InitFixtures(&testfixtures.SQLite{}, "fixtures/")
37+
}
38+
2039
func TestMain(m *testing.M) {
2140
if err := CreateTestEngine(); err != nil {
2241
fmt.Printf("Error creating test engine: %v\n", err)

models/unit_tests.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,13 @@ package models
77
import (
88
"testing"
99

10-
"github.com/go-xorm/core"
1110
"github.com/go-xorm/xorm"
12-
_ "github.com/mattn/go-sqlite3" // for the test engine
1311
"github.com/stretchr/testify/assert"
14-
"gopkg.in/testfixtures.v2"
1512
)
1613

1714
// NonexistentID an ID that will never exist
1815
const NonexistentID = 9223372036854775807
1916

20-
// CreateTestEngine create an xorm engine for testing
21-
func CreateTestEngine() error {
22-
var err error
23-
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
24-
if err != nil {
25-
return err
26-
}
27-
x.SetMapper(core.GonicMapper{})
28-
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
29-
return err
30-
}
31-
32-
return InitFixtures(&testfixtures.SQLite{}, "fixtures/")
33-
}
34-
3517
// PrepareTestDatabase load test fixtures into test database
3618
func PrepareTestDatabase() error {
3719
return LoadFixtures()

0 commit comments

Comments
 (0)