shiori/internal/testutil/shiori.go
Monirzadeh 82aa1e5080
fix: fixes path issues on windows (#829)
* return corrent path in windows with usiing path lib

* ci: run tests in windows and macos too

* avoid testing mysql/psql in windows and macos

* windows & macos matrix

* disable gotestfmt

* replace which in shell script

* handle error in test db removal

* fix expected path baseed on platform

* add leading seprator

* proper temporary storage dir and db cleanup

* fix failed to create destination dir file does not exist in windows

* move temp to /tmp

* update temp folder

* fix config tests in windows

* apply patch for db

* revert temp dir creation.

* unify account db tests pach

* remove TmpDir for sqlite tests

* try to force CGO disable with enviroment variable

* Remove unneeded log

Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>

* remove unneeded comment

Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>

* fix file path for download images

* change way to create temp directory

* use diffrent file name for each test

* fix typo

* fix absolute path in successful download image

* correct filename with png

* change test to download image from internet instead of local machine

* remvoe unneeded import

* remove os.RemoveAll(.env)

* unify variable names in unit test

* return CGO_ENABLED=0

* test other way to set enviroment variable

* try to set enviroment variable sepratly in macos and windows

* set enviroment variable before run commands in windows

* fix windows test name

* combine two workflow for windows and macos again

* fix typo

* remove env

* change env path

* cleanup unneeded env

* general CGO_ENABLED environ

* use absolute path to run fileserver instead of relative

* serve file test from internet shiori repository

* check file existance after download and unify varibale name from temp to tmpDir

* remove unneeded log

---------

Co-authored-by: Felipe M <me@fmartingr.com>
Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>
2024-02-05 10:21:23 +01:00

56 lines
1.5 KiB
Go

package testutil
import (
"context"
"os"
"testing"
"github.com/go-shiori/shiori/internal/config"
"github.com/go-shiori/shiori/internal/database"
"github.com/go-shiori/shiori/internal/dependencies"
"github.com/go-shiori/shiori/internal/domains"
"github.com/go-shiori/shiori/internal/model"
"github.com/gofrs/uuid/v5"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
)
func GetTestConfigurationAndDependencies(t *testing.T, ctx context.Context, logger *logrus.Logger) (*config.Config, *dependencies.Dependencies) {
t.Helper()
tmp, err := os.CreateTemp("", "")
require.NoError(t, err)
t.Cleanup(func() {
os.Remove(tmp.Name())
})
cfg := config.ParseServerConfiguration(ctx, logger)
cfg.Http.SecretKey = []byte("test")
tmpDir, err := os.MkdirTemp("", "")
require.NoError(t, err)
db, err := database.OpenSQLiteDatabase(ctx, tmp.Name())
require.NoError(t, err)
require.NoError(t, db.Migrate())
cfg.Storage.DataDir = tmpDir
deps := dependencies.NewDependencies(logger, db, cfg)
deps.Database = db
deps.Domains.Auth = domains.NewAccountsDomain(deps)
deps.Domains.Archiver = domains.NewArchiverDomain(deps)
deps.Domains.Bookmarks = domains.NewBookmarksDomain(deps)
deps.Domains.Storage = domains.NewStorageDomain(deps, afero.NewBasePathFs(afero.NewOsFs(), cfg.Storage.DataDir))
return cfg, deps
}
func GetValidBookmark() *model.BookmarkDTO {
uuidV4, _ := uuid.NewV4()
return &model.BookmarkDTO{
URL: "https://github.com/go-shiori/shiori#" + uuidV4.String(),
Title: "Shiori repository",
}
}