Fix API tests

This commit is contained in:
viktorstrate
2022-07-08 17:44:03 +02:00
parent 214aa389fb
commit 831e24f654
5 changed files with 22 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package scanner_task
import (
"context"
"database/sql"
"flag"
"io/fs"
"github.com/photoview/photoview/api/graphql/models"
@@ -84,6 +85,11 @@ func (c TaskContext) Value(key interface{}) interface{} {
}
func (c TaskContext) WithDB(db *gorm.DB) TaskContext {
// Allow db to be nil in tests
if db == nil && flag.Lookup("test.v") != nil {
return c
}
return c.WithValue(taskCtxKeyDatabase, db.WithContext(c.ctx))
}