refactor: remove environment variable requirements for go test
This commit is contained in:
parent
65ef54f623
commit
591a646f84
|
|
@ -65,8 +65,6 @@ func CreateTestEngine() (engine *xorm.Engine, err error) {
|
||||||
func InitTestFixtures(tablenames ...string) (err error) {
|
func InitTestFixtures(tablenames ...string) (err error) {
|
||||||
// Create all fixtures
|
// Create all fixtures
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
// Sync fixtures
|
// Sync fixtures
|
||||||
err = InitFixtures(tablenames...)
|
err = InitFixtures(tablenames...)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -28,13 +29,16 @@ import (
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fixtures *testfixtures.Loader
|
var (
|
||||||
|
fixtures *testfixtures.Loader
|
||||||
|
//go:embed fixtures
|
||||||
|
fixturesFS embed.FS
|
||||||
|
)
|
||||||
|
|
||||||
// InitFixtures initialize test fixtures for a test database
|
// InitFixtures initialize test fixtures for a test database
|
||||||
func InitFixtures(tablenames ...string) (err error) {
|
func InitFixtures(tablenames ...string) (err error) {
|
||||||
|
|
||||||
var testfiles func(loader *testfixtures.Loader) error
|
var testfiles func(loader *testfixtures.Loader) error
|
||||||
dir := filepath.Join(config.ServiceRootpath.GetString(), "pkg", "db", "fixtures")
|
dir := "fixtures"
|
||||||
|
|
||||||
// If fixture table names are specified, load them
|
// If fixture table names are specified, load them
|
||||||
// Otherwise, load all fixtures
|
// Otherwise, load all fixtures
|
||||||
|
|
@ -48,6 +52,7 @@ func InitFixtures(tablenames ...string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
loaderOptions := []func(loader *testfixtures.Loader) error{
|
loaderOptions := []func(loader *testfixtures.Loader) error{
|
||||||
|
testfixtures.FS(fixturesFS),
|
||||||
testfixtures.Database(x.DB().DB),
|
testfixtures.Database(x.DB().DB),
|
||||||
testfixtures.Dialect(GetDialect()),
|
testfixtures.Dialect(GetDialect()),
|
||||||
testfixtures.DangerousSkipTestDatabaseCheck(),
|
testfixtures.DangerousSkipTestDatabaseCheck(),
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,6 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// Set default config
|
// Set default config
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
i18n.Init()
|
i18n.Init()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// Set default config
|
// Set default config
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
// Some tests use the file engine, so we'll need to initialize that
|
// Some tests use the file engine, so we'll need to initialize that
|
||||||
files.InitTests()
|
files.InitTests()
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -27,6 +28,8 @@ import (
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// Initialize logger for tests
|
// Initialize logger for tests
|
||||||
log.InitLogger()
|
log.InitLogger()
|
||||||
|
config.ServicePublicURL.Set("https://localhost")
|
||||||
|
config.InitConfig()
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertTodoistToVikunja(t *testing.T) {
|
func TestConvertTodoistToVikunja(t *testing.T) {
|
||||||
|
|
||||||
config.InitConfig()
|
|
||||||
|
|
||||||
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
|
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
time1 = time1.In(config.GetTimeZone())
|
time1 = time1.In(config.GetTimeZone())
|
||||||
|
|
@ -48,7 +45,7 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
||||||
dueTimeWithTime = dueTimeWithTime.In(config.GetTimeZone())
|
dueTimeWithTime = dueTimeWithTime.In(config.GetTimeZone())
|
||||||
nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z")
|
nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/testimage.jpg")
|
exampleFile, err := os.ReadFile("../testimage.jpg")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
makeTestItem := func(id, projectId string, hasDueDate, hasLabels, done bool) *item {
|
makeTestItem := func(id, projectId string, hasDueDate, hasLabels, done bool) *item {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -27,6 +28,8 @@ import (
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// Initialize logger for tests
|
// Initialize logger for tests
|
||||||
log.InitLogger()
|
log.InitLogger()
|
||||||
|
config.ServicePublicURL.Set("https://localhost")
|
||||||
|
config.InitConfig()
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
|
|
||||||
|
|
@ -33,9 +32,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) {
|
func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) {
|
||||||
|
|
||||||
config.InitConfig()
|
|
||||||
|
|
||||||
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
|
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
@ -240,7 +236,7 @@ func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) {
|
||||||
func TestConvertTrelloToVikunja(t *testing.T) {
|
func TestConvertTrelloToVikunja(t *testing.T) {
|
||||||
trelloData, time1 := getTestBoard(t)
|
trelloData, time1 := getTestBoard(t)
|
||||||
|
|
||||||
exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/testimage.jpg")
|
exampleFile, err := os.ReadFile("../testimage.jpg")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedHierarchyOrg := map[string][]*models.ProjectWithTasksAndBuckets{
|
expectedHierarchyOrg := map[string][]*models.ProjectWithTasksAndBuckets{
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// Set default config
|
// Set default config
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
// Some tests use the file engine, so we'll need to initialize that
|
// Some tests use the file engine, so we'll need to initialize that
|
||||||
files.InitTests()
|
files.InitTests()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
|
|
@ -34,7 +33,7 @@ func TestVikunjaFileMigrator_Migrate(t *testing.T) {
|
||||||
m := &FileMigrator{}
|
m := &FileMigrator{}
|
||||||
u := &user.User{ID: 1}
|
u := &user.User{ID: 1}
|
||||||
|
|
||||||
f, err := os.Open(config.ServiceRootpath.GetString() + "/pkg/modules/migration/vikunja-file/export.zip")
|
f, err := os.Open("export.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not open file: %s", err)
|
t.Fatalf("Could not open file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +80,7 @@ func TestVikunjaFileMigrator_Migrate(t *testing.T) {
|
||||||
m := &FileMigrator{}
|
m := &FileMigrator{}
|
||||||
u := &user.User{ID: 1}
|
u := &user.User{ID: 1}
|
||||||
|
|
||||||
f, err := os.Open(config.ServiceRootpath.GetString() + "/pkg/modules/migration/vikunja-file/export_pre_0.21.0.zip")
|
f, err := os.Open("export_pre_0.21.0.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not open file: %s", err)
|
t.Fatalf("Could not open file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,6 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// Set default config
|
// Set default config
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
SetupTests()
|
SetupTests()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -65,8 +64,7 @@ var (
|
||||||
|
|
||||||
func setupTestEnv() (e *echo.Echo, err error) {
|
func setupTestEnv() (e *echo.Echo, err error) {
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
config.ServicePublicURL.Set("https://localhost")
|
||||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
|
||||||
|
|
||||||
// Initialize logger for tests
|
// Initialize logger for tests
|
||||||
log.InitLogger()
|
log.InitLogger()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue