Fix the coverage for codecov. (#1251)

This commit is contained in:
Googol Lee
2025-07-18 15:21:03 +02:00
committed by GitHub
parent d7cc42ed6e
commit 50209bc55c
8 changed files with 32 additions and 32 deletions

View File

@@ -3,18 +3,13 @@ package log
import (
"bytes"
"context"
"flag"
"log/slog"
"testing"
"github.com/google/go-cmp/cmp"
_ "github.com/photoview/photoview/api/test_utils/flags"
)
func init() {
// Avoid panic with providing flags in `test_utils/integration_setup.go`.
flag.CommandLine.Init("executable_worker", flag.ContinueOnError)
}
func mockDefaultLogger(t *testing.T) *bytes.Buffer {
t.Helper()

View File

@@ -1,20 +1,16 @@
package executable_worker
import (
"flag"
"path/filepath"
"runtime"
"strings"
"testing"
_ "github.com/photoview/photoview/api/test_utils/flags"
)
const testdataBinPath = "./test_data/mock_bin"
func init() {
// Avoid panic with providing flags in `test_utils/integration_setup.go`.
flag.CommandLine.Init("executable_worker", flag.ContinueOnError)
}
// SetPathWithCurrent sets PATH env to `paths` in the directory of testing files. The PATH will restore to the previous value when the test is done.
func SetPathWithCurrent(t *testing.T, paths ...string) {
_, file, _, ok := runtime.Caller(1)

View File

@@ -1,13 +1,13 @@
package media_type
import (
"flag"
"testing"
"github.com/photoview/photoview/api/test_utils"
)
func init() {
// Avoid panic with providing flags in `test_utils/integration_setup.go`.
flag.CommandLine.Init("media_type", flag.ContinueOnError)
func TestMain(m *testing.M) {
test_utils.UnitTestRun(m)
}
type boolImage bool

View File

@@ -0,0 +1,16 @@
package flags
import "flag"
var (
// Database enables database-integration tests when the `-database` flag is passed to `go test`.
Database bool
// Filesystem enables filesystem-integration tests when the `-filesystem` flag is passed to `go test`.
Filesystem bool
)
func init() {
flag.BoolVar(&Database, "database", false, "run database integration tests")
flag.BoolVar(&Filesystem, "filesystem", false, "run filesystem integration tests")
}

View File

@@ -9,20 +9,11 @@ import (
"github.com/joho/godotenv"
"github.com/photoview/photoview/api/scanner/media_encoding/executable_worker"
"github.com/photoview/photoview/api/test_utils/flags"
"github.com/photoview/photoview/api/utils"
"gorm.io/gorm"
)
type integration_options struct {
Database *bool
Filesystem *bool
}
var integration_flags integration_options = integration_options{
Database: flag.Bool("database", false, "run database integration tests"),
Filesystem: flag.Bool("filesystem", false, "run filesystem integration tests"),
}
var test_dbm TestDBManager = TestDBManager{}
func UnitTestRun(m *testing.M) int {
@@ -38,7 +29,7 @@ func IntegrationTestRun(m *testing.M) int {
log.Fatal("could not get runtime file path")
}
if *integration_flags.Database {
if flags.Database {
envPath := path.Join(path.Dir(file), "..", "testing.env")
@@ -61,14 +52,14 @@ func IntegrationTestRun(m *testing.M) int {
}
func FilesystemTest(t *testing.T) {
if !*integration_flags.Filesystem {
if !flags.Filesystem {
t.Skip("Filesystem integration tests disabled")
}
utils.ConfigureTestCache(t.TempDir())
}
func DatabaseTest(t *testing.T) *gorm.DB {
if !*integration_flags.Database {
if !flags.Database {
t.Skip("Database integration tests disabled")
}

View File

@@ -40,7 +40,7 @@ func (dbm *TestDBManager) Close() error {
func (dbm *TestDBManager) setup() error {
config := gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
Logger: logger.Default.LogMode(logger.Warn),
}
db, err := database.ConfigureDatabase(&config)
if err != nil {