mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 18:29:17 +00:00
Fix API tests
This commit is contained in:
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
@@ -19,6 +19,7 @@ jobs:
|
|||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
target_platform:
|
target_platform:
|
||||||
- "linux/amd64"
|
- "linux/amd64"
|
||||||
@@ -134,7 +135,7 @@ jobs:
|
|||||||
docker manifest create ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGES}
|
docker manifest create ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGES}
|
||||||
docker manifest push ${DOCKER_IMAGE}:${TAG}
|
docker manifest push ${DOCKER_IMAGE}:${TAG}
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Cleanup tags
|
- name: Cleanup tags
|
||||||
run: |
|
run: |
|
||||||
ACCESS_TOKEN=$(curl -X POST \
|
ACCESS_TOKEN=$(curl -X POST \
|
||||||
@@ -142,18 +143,18 @@ jobs:
|
|||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-d "{\"username\":\"${DOCKER_USERNAME}\",\"password\":\"${DOCKER_PASSWORD}\"}" \
|
-d "{\"username\":\"${DOCKER_USERNAME}\",\"password\":\"${DOCKER_PASSWORD}\"}" \
|
||||||
https://hub.docker.com/v2/users/login/ | jq --raw-output '.token')
|
https://hub.docker.com/v2/users/login/ | jq --raw-output '.token')
|
||||||
|
|
||||||
PLATFORMS=("amd64" "arm64" "arm-v7" "arm-v6")
|
PLATFORMS=("amd64" "arm64" "arm-v7" "arm-v6")
|
||||||
for PLATFORM in ${PLATFORMS[@]}; do
|
for PLATFORM in ${PLATFORMS[@]}; do
|
||||||
TAG="linux-${PLATFORM}-${GITHUB_SHA::8}-${{ github.event_name }}"
|
TAG="linux-${PLATFORM}-${GITHUB_SHA::8}-${{ github.event_name }}"
|
||||||
echo "Deleting tag: ${DOCKER_IMAGE}:${TAG}"
|
echo "Deleting tag: ${DOCKER_IMAGE}:${TAG}"
|
||||||
|
|
||||||
curl -X DELETE \
|
curl -X DELETE \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: JWT ${ACCESS_TOKEN}" \
|
-H "Authorization: JWT ${ACCESS_TOKEN}" \
|
||||||
https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/${TAG}/
|
https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/${TAG}/
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Clear
|
- name: Clear
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,7 +1,8 @@
|
|||||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
cache/
|
cache/
|
||||||
media_cache/
|
/media_cache/
|
||||||
|
/api/media_cache/
|
||||||
/photos_path
|
/photos_path
|
||||||
photoview.db
|
photoview.db
|
||||||
photoview.db-journal
|
photoview.db-journal
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package scanner_queue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/graphql/models"
|
"github.com/photoview/photoview/api/graphql/models"
|
||||||
@@ -9,6 +10,9 @@ import (
|
|||||||
"github.com/photoview/photoview/api/scanner/scanner_task"
|
"github.com/photoview/photoview/api/scanner/scanner_task"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ = flag.Bool("database", false, "run database integration tests")
|
||||||
|
var _ = flag.Bool("filesystem", false, "run filesystem integration tests")
|
||||||
|
|
||||||
func makeAlbumWithID(id int) *models.Album {
|
func makeAlbumWithID(id int) *models.Album {
|
||||||
var album models.Album
|
var album models.Album
|
||||||
album.ID = id
|
album.ID = id
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package scanner_task
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"flag"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/graphql/models"
|
"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 {
|
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))
|
return c.WithValue(taskCtxKeyDatabase, db.WithContext(c.ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(test_utils.IntegrationTestRun(m))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCleanupMedia(t *testing.T) {
|
func TestCleanupMedia(t *testing.T) {
|
||||||
test_utils.FilesystemTest(t)
|
test_utils.FilesystemTest(t)
|
||||||
db := test_utils.DatabaseTest(t)
|
db := test_utils.DatabaseTest(t)
|
||||||
@@ -27,7 +31,7 @@ func TestCleanupMedia(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_dir := t.TempDir()
|
test_dir := t.TempDir()
|
||||||
copy.Copy("./test_data", test_dir)
|
assert.NoError(t, copy.Copy("../../test_data", test_dir))
|
||||||
|
|
||||||
countAllMedia := func() int {
|
countAllMedia := func() int {
|
||||||
var all_media []*models.Media
|
var all_media []*models.Media
|
||||||
|
|||||||
Reference in New Issue
Block a user