diff --git a/pkg/db/test.go b/pkg/db/test.go index 538189c15..a2e8e6366 100644 --- a/pkg/db/test.go +++ b/pkg/db/test.go @@ -65,8 +65,6 @@ func CreateTestEngine() (engine *xorm.Engine, err error) { func InitTestFixtures(tablenames ...string) (err error) { // Create all fixtures 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 err = InitFixtures(tablenames...) diff --git a/pkg/db/test_fixtures.go b/pkg/db/test_fixtures.go index a18d51df9..26379bc48 100644 --- a/pkg/db/test_fixtures.go +++ b/pkg/db/test_fixtures.go @@ -17,6 +17,7 @@ package db import ( + "embed" "fmt" "path/filepath" "testing" @@ -28,13 +29,16 @@ import ( "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 func InitFixtures(tablenames ...string) (err 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 // Otherwise, load all fixtures @@ -48,6 +52,7 @@ func InitFixtures(tablenames ...string) (err error) { } loaderOptions := []func(loader *testfixtures.Loader) error{ + testfixtures.FS(fixturesFS), testfixtures.Database(x.DB().DB), testfixtures.Dialect(GetDialect()), testfixtures.DangerousSkipTestDatabaseCheck(), diff --git a/pkg/models/main_test.go b/pkg/models/main_test.go index 6c755b13a..2adb06900 100644 --- a/pkg/models/main_test.go +++ b/pkg/models/main_test.go @@ -60,8 +60,6 @@ func TestMain(m *testing.M) { // Set default config 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() diff --git a/pkg/modules/migration/main_test.go b/pkg/modules/migration/main_test.go index b68acc07a..a9a671357 100644 --- a/pkg/modules/migration/main_test.go +++ b/pkg/modules/migration/main_test.go @@ -36,8 +36,6 @@ func TestMain(m *testing.M) { // Set default config 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 files.InitTests() diff --git a/pkg/modules/migration/todoist/main_test.go b/pkg/modules/migration/todoist/main_test.go index f7d79bdee..f9afe9d15 100644 --- a/pkg/modules/migration/todoist/main_test.go +++ b/pkg/modules/migration/todoist/main_test.go @@ -20,6 +20,7 @@ import ( "os" "testing" + "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" ) @@ -27,6 +28,8 @@ import ( func TestMain(m *testing.M) { // Initialize logger for tests log.InitLogger() + config.ServicePublicURL.Set("https://localhost") + config.InitConfig() os.Exit(m.Run()) } diff --git a/pkg/modules/migration/todoist/todoist_test.go b/pkg/modules/migration/todoist/todoist_test.go index b524f74d5..df95ecbef 100644 --- a/pkg/modules/migration/todoist/todoist_test.go +++ b/pkg/modules/migration/todoist/todoist_test.go @@ -31,9 +31,6 @@ import ( ) func TestConvertTodoistToVikunja(t *testing.T) { - - config.InitConfig() - time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z") require.NoError(t, err) time1 = time1.In(config.GetTimeZone()) @@ -48,7 +45,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { dueTimeWithTime = dueTimeWithTime.In(config.GetTimeZone()) nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z") 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) makeTestItem := func(id, projectId string, hasDueDate, hasLabels, done bool) *item { diff --git a/pkg/modules/migration/trello/main_test.go b/pkg/modules/migration/trello/main_test.go index d665cd3ba..95c025b59 100644 --- a/pkg/modules/migration/trello/main_test.go +++ b/pkg/modules/migration/trello/main_test.go @@ -20,6 +20,7 @@ import ( "os" "testing" + "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" ) @@ -27,6 +28,8 @@ import ( func TestMain(m *testing.M) { // Initialize logger for tests log.InitLogger() + config.ServicePublicURL.Set("https://localhost") + config.InitConfig() os.Exit(m.Run()) } diff --git a/pkg/modules/migration/trello/trello_test.go b/pkg/modules/migration/trello/trello_test.go index 2ce551725..563b4afc8 100644 --- a/pkg/modules/migration/trello/trello_test.go +++ b/pkg/modules/migration/trello/trello_test.go @@ -22,7 +22,6 @@ import ( "testing" "time" - "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/models" @@ -33,9 +32,6 @@ import ( ) func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) { - - config.InitConfig() - time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z") require.NoError(t, err) @@ -240,7 +236,7 @@ func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) { func TestConvertTrelloToVikunja(t *testing.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) expectedHierarchyOrg := map[string][]*models.ProjectWithTasksAndBuckets{ diff --git a/pkg/modules/migration/vikunja-file/main_test.go b/pkg/modules/migration/vikunja-file/main_test.go index e3bbfba9a..e723ba586 100644 --- a/pkg/modules/migration/vikunja-file/main_test.go +++ b/pkg/modules/migration/vikunja-file/main_test.go @@ -36,8 +36,6 @@ func TestMain(m *testing.M) { // Set default config 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 files.InitTests() diff --git a/pkg/modules/migration/vikunja-file/vikunja_test.go b/pkg/modules/migration/vikunja-file/vikunja_test.go index a343e0920..848f568b7 100644 --- a/pkg/modules/migration/vikunja-file/vikunja_test.go +++ b/pkg/modules/migration/vikunja-file/vikunja_test.go @@ -20,7 +20,6 @@ import ( "os" "testing" - "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/user" @@ -34,7 +33,7 @@ func TestVikunjaFileMigrator_Migrate(t *testing.T) { m := &FileMigrator{} 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 { t.Fatalf("Could not open file: %s", err) } @@ -81,7 +80,7 @@ func TestVikunjaFileMigrator_Migrate(t *testing.T) { m := &FileMigrator{} 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 { t.Fatalf("Could not open file: %s", err) } diff --git a/pkg/notifications/main_test.go b/pkg/notifications/main_test.go index 85fb79b2f..89d1cd2fd 100644 --- a/pkg/notifications/main_test.go +++ b/pkg/notifications/main_test.go @@ -50,8 +50,6 @@ func TestMain(m *testing.M) { // Set default config 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() diff --git a/pkg/webtests/integrations.go b/pkg/webtests/integrations.go index 86cdd4de1..67a3ad400 100644 --- a/pkg/webtests/integrations.go +++ b/pkg/webtests/integrations.go @@ -21,7 +21,6 @@ import ( "net/http" "net/http/httptest" "net/url" - "os" "strings" "testing" @@ -65,8 +64,7 @@ var ( func setupTestEnv() (e *echo.Echo, err error) { 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")) + config.ServicePublicURL.Set("https://localhost") // Initialize logger for tests log.InitLogger()