From 831e24f6547cf8cbd28e4db0e68c4705b5be01ff Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Fri, 8 Jul 2022 17:44:03 +0200 Subject: [PATCH] Fix API tests --- .github/workflows/build.yml | 9 +++++---- .gitignore | 3 ++- api/scanner/scanner_queue/queue_test.go | 4 ++++ api/scanner/scanner_task/scanner_task.go | 6 ++++++ .../scanner_tasks/cleanup_tasks/cleanup_media_test.go | 6 +++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a042ebaa0..436aed4bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,7 @@ jobs: runs-on: ubuntu-20.04 strategy: + fail-fast: false matrix: target_platform: - "linux/amd64" @@ -134,7 +135,7 @@ jobs: docker manifest create ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGES} docker manifest push ${DOCKER_IMAGE}:${TAG} done - + - name: Cleanup tags run: | ACCESS_TOKEN=$(curl -X POST \ @@ -142,18 +143,18 @@ jobs: -H "Accept: application/json" \ -d "{\"username\":\"${DOCKER_USERNAME}\",\"password\":\"${DOCKER_PASSWORD}\"}" \ https://hub.docker.com/v2/users/login/ | jq --raw-output '.token') - + PLATFORMS=("amd64" "arm64" "arm-v7" "arm-v6") for PLATFORM in ${PLATFORMS[@]}; do TAG="linux-${PLATFORM}-${GITHUB_SHA::8}-${{ github.event_name }}" echo "Deleting tag: ${DOCKER_IMAGE}:${TAG}" - + curl -X DELETE \ -H "Accept: application/json" \ -H "Authorization: JWT ${ACCESS_TOKEN}" \ https://hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/${TAG}/ done - + - name: Clear if: always() run: | diff --git a/.gitignore b/.gitignore index 9561a5814..fc0762c47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # See https://help.github.com/ignore-files/ for more about ignoring files. cache/ -media_cache/ +/media_cache/ +/api/media_cache/ /photos_path photoview.db photoview.db-journal diff --git a/api/scanner/scanner_queue/queue_test.go b/api/scanner/scanner_queue/queue_test.go index 0f01b293e..2b2db9642 100644 --- a/api/scanner/scanner_queue/queue_test.go +++ b/api/scanner/scanner_queue/queue_test.go @@ -2,6 +2,7 @@ package scanner_queue import ( "context" + "flag" "testing" "github.com/photoview/photoview/api/graphql/models" @@ -9,6 +10,9 @@ import ( "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 { var album models.Album album.ID = id diff --git a/api/scanner/scanner_task/scanner_task.go b/api/scanner/scanner_task/scanner_task.go index b924fb197..110238a7d 100644 --- a/api/scanner/scanner_task/scanner_task.go +++ b/api/scanner/scanner_task/scanner_task.go @@ -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)) } diff --git a/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go b/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go index 6de038ef7..a58484d4c 100644 --- a/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go +++ b/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go @@ -13,6 +13,10 @@ import ( "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + os.Exit(test_utils.IntegrationTestRun(m)) +} + func TestCleanupMedia(t *testing.T) { test_utils.FilesystemTest(t) db := test_utils.DatabaseTest(t) @@ -27,7 +31,7 @@ func TestCleanupMedia(t *testing.T) { } test_dir := t.TempDir() - copy.Copy("./test_data", test_dir) + assert.NoError(t, copy.Copy("../../test_data", test_dir)) countAllMedia := func() int { var all_media []*models.Media