navidrome/tests/init_tests.go
Deluan Quintão 1286fdfc9c
chore(lint): enable thelper (#6488)
thelper requires test helpers to call t.Helper() first, so failures point
at the caller, and keeps the testing param first. Fixed 7 sites by hand:
4 helpers now call Helper(), 3 subtest bodies inlined into t.Run.
The parameter name checks are off: renaming t to tb adds churn, not
better line numbers.
2026-11-16 23:38:07 -05:00

39 lines
858 B
Go

package tests
import (
"os"
"path/filepath"
"runtime"
"sync"
"testing"
"github.com/navidrome/navidrome/conf"
_ "github.com/navidrome/navidrome/conf/mime" // registers mime_types.yaml, so tests see the same image types as the server
"github.com/navidrome/navidrome/log"
)
var (
once sync.Once
appPath string
)
func Init(t testing.TB, skipOnShort bool) {
t.Helper()
if skipOnShort && testing.Short() {
t.Skip("skipping test in short mode.")
}
once.Do(func() {
_, file, _, _ := runtime.Caller(0)
appPath, _ = filepath.Abs(filepath.Join(filepath.Dir(file), ".."))
confPath := filepath.Join(appPath, "tests", "navidrome-test.toml")
println("Loading test configuration file from " + confPath)
conf.LoadFromFile(confPath)
noLog := os.Getenv("NOLOG")
if noLog != "" {
log.SetLevel(log.LevelError)
}
})
t.Chdir(appPath)
}