Skip to content

Commit

Permalink
Fix API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorstrate committed Jul 8, 2022
1 parent 214aa38 commit 831e24f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
target_platform:
- "linux/amd64"
Expand Down Expand Up @@ -134,26 +135,26 @@ 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 \
-H "Content-Type: application/json" \
-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: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions api/scanner/scanner_queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package scanner_queue

import (
"context"
"flag"
"testing"

"github.com/photoview/photoview/api/graphql/models"
"github.com/photoview/photoview/api/scanner/scanner_cache"
"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
Expand Down
6 changes: 6 additions & 0 deletions api/scanner/scanner_task/scanner_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scanner_task
import (
"context"
"database/sql"
"flag"
"io/fs"

"github.com/photoview/photoview/api/graphql/models"
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 831e24f

Please sign in to comment.