mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 13:58:54 +00:00
Fix the coverage for codecov. (#1251)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,7 +21,7 @@ node_modules/
|
||||
|
||||
# testing
|
||||
/ui/coverage
|
||||
/api/coverage.txt
|
||||
/api/coverage*
|
||||
/api/test-*-report.xml
|
||||
*.cov
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
16
api/test_utils/flags/flags.go
Normal file
16
api/test_utils/flags/flags.go
Normal 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")
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
set -euxo pipefail
|
||||
|
||||
cd "$(dirname $0)/../api"
|
||||
go test ./... -v -database -filesystem -p 1 -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic 2>&1 | tee >(go-junit-report >test-api-coverage-report.xml)
|
||||
go test ./... -v -database -filesystem -p 1 \
|
||||
-cover -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic \
|
||||
2>&1 | tee >(go-junit-report >test-api-coverage-report.xml)
|
||||
|
||||
Reference in New Issue
Block a user