Skip to content

Fix compiling without sqlite and gcc #2177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions models/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (

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

"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"
)

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

// CreateTestEngine create an xorm engine for testing
func CreateTestEngine() error {
var err error
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
if err != nil {
return err
}
x.SetMapper(core.GonicMapper{})
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
return err
}

return InitFixtures(&testfixtures.SQLite{}, "fixtures/")
}

func TestMain(m *testing.M) {
if err := CreateTestEngine(); err != nil {
fmt.Printf("Error creating test engine: %v\n", err)
Expand Down
18 changes: 0 additions & 18 deletions models/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ package models
import (
"testing"

"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"
)

// NonexistentID an ID that will never exist
const NonexistentID = 9223372036854775807

// CreateTestEngine create an xorm engine for testing
func CreateTestEngine() error {
var err error
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
if err != nil {
return err
}
x.SetMapper(core.GonicMapper{})
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
return err
}

return InitFixtures(&testfixtures.SQLite{}, "fixtures/")
}

// PrepareTestDatabase load test fixtures into test database
func PrepareTestDatabase() error {
return LoadFixtures()
Expand Down