Include a group of small but real media files for testing. (#1131)
* Move scanner/test_data/* to a stand-alone directory. * Include real medias. * Rename testdata to test_data * Rename test_data/scanner -> test_data/library * Clean tests to avoid depneding env. * Rename: scanner/test_data -> scanner/test_media * Rename: test_data/bin -> test_data/mock_bin * Fix paths in tests.
@@ -5,6 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/graphql/models"
|
"github.com/photoview/photoview/api/graphql/models"
|
||||||
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
|
"github.com/photoview/photoview/api/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,6 +55,9 @@ func TestMediaURLCachePath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMediaURLGetURL(t *testing.T) {
|
func TestMediaURLGetURL(t *testing.T) {
|
||||||
|
done := test_utils.SetEnv(string(utils.EnvAPIEndpoint), "")
|
||||||
|
defer done()
|
||||||
|
|
||||||
photo := models.MediaURL{
|
photo := models.MediaURL{
|
||||||
MediaName: "photo.jpg",
|
MediaName: "photo.jpg",
|
||||||
ContentType: mimeJpeg,
|
ContentType: mimeJpeg,
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package executable_worker
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/test_utils/test_env"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testdataBinPath = "./testdata/bin"
|
const testdataBinPath = "./test_data/mock_bin"
|
||||||
|
|
||||||
func TestInitFfprobePath(t *testing.T) {
|
func TestInitFfprobePath(t *testing.T) {
|
||||||
t.Run("PathFail", func(t *testing.T) {
|
t.Run("PathFail", func(t *testing.T) {
|
||||||
@@ -17,10 +17,10 @@ func TestInitFfprobePath(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("VersionFail", func(t *testing.T) {
|
t.Run("VersionFail", func(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
err := SetFfprobePath()
|
err := SetFfprobePath()
|
||||||
@@ -30,7 +30,7 @@ func TestInitFfprobePath(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Succeed", func(t *testing.T) {
|
t.Run("Succeed", func(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
err := SetFfprobePath()
|
err := SetFfprobePath()
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/test_utils/test_env"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
"github.com/photoview/photoview/api/utils"
|
"github.com/photoview/photoview/api/utils"
|
||||||
"gopkg.in/vansante/go-ffprobe.v2"
|
"gopkg.in/vansante/go-ffprobe.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFfmpegNotExist(t *testing.T) {
|
func TestFfmpegNotExist(t *testing.T) {
|
||||||
done := test_env.SetPathWithCurrent()
|
done := test_utils.SetPathWithCurrent()
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
@@ -34,10 +34,10 @@ func TestFfmpegNotExist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFfmpegVersionFail(t *testing.T) {
|
func TestFfmpegVersionFail(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
@@ -60,10 +60,10 @@ func TestFfmpegVersionFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFfmpegIgnore(t *testing.T) {
|
func TestFfmpegIgnore(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
doneEnv := test_env.SetEnv("PHOTOVIEW_DISABLE_VIDEO_ENCODING", "true")
|
doneEnv := test_utils.SetEnv("PHOTOVIEW_DISABLE_VIDEO_ENCODING", "true")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
@@ -86,7 +86,7 @@ func TestFfmpegIgnore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFfmpeg(t *testing.T) {
|
func TestFfmpeg(t *testing.T) {
|
||||||
done := test_env.SetPathWithCurrent(testdataBinPath)
|
done := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
@@ -96,14 +96,14 @@ func TestFfmpeg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("EncodeMp4Failed", func(t *testing.T) {
|
t.Run("EncodeMp4Failed", func(t *testing.T) {
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
err := Ffmpeg.EncodeMp4("input", "output")
|
err := Ffmpeg.EncodeMp4("input", "output")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
||||||
}
|
}
|
||||||
if got, want := err.Error(), `^encoding video with ".*/testdata/bin/ffmpeg" \[-i input -vcodec h264 .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
if got, want := err.Error(), `^encoding video with ".*/test_data/mock_bin/ffmpeg" \[-i input -vcodec h264 .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
||||||
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -121,14 +121,14 @@ func TestFfmpeg(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
t.Run("EncodeVideoThumbnailMp4Failed", func(t *testing.T) {
|
t.Run("EncodeVideoThumbnailMp4Failed", func(t *testing.T) {
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
err := Ffmpeg.EncodeVideoThumbnail("input", "output", probeData)
|
err := Ffmpeg.EncodeVideoThumbnail("input", "output", probeData)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Ffmpeg.EncodeVideoThumbnail(...) = nil, should be an error.")
|
t.Fatalf("Ffmpeg.EncodeVideoThumbnail(...) = nil, should be an error.")
|
||||||
}
|
}
|
||||||
if got, want := err.Error(), `^encoding video thumbnail with ".*/testdata/bin/ffmpeg" \[-ss 2 -i input .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
if got, want := err.Error(), `^encoding video thumbnail with ".*/test_data/mock_bin/ffmpeg" \[-ss 2 -i input .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
||||||
t.Errorf("Ffmpeg.EncodeVideoThumbnail(...) = %q, should be as reg pattern %q", got, want)
|
t.Errorf("Ffmpeg.EncodeVideoThumbnail(...) = %q, should be as reg pattern %q", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -142,43 +142,43 @@ func TestFfmpeg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFfmpegWithHWAcc(t *testing.T) {
|
func TestFfmpegWithHWAcc(t *testing.T) {
|
||||||
doneCodec := test_env.SetEnv(utils.EnvVideoHardwareAcceleration.GetName(), "qsv")
|
doneCodec := test_utils.SetEnv(utils.EnvVideoHardwareAcceleration.GetName(), "qsv")
|
||||||
defer doneCodec()
|
defer doneCodec()
|
||||||
|
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
|
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
err := Ffmpeg.EncodeMp4("input", "output")
|
err := Ffmpeg.EncodeMp4("input", "output")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
||||||
}
|
}
|
||||||
if got, want := err.Error(), `^encoding video with ".*/testdata/bin/ffmpeg" \[-i input -vcodec h264_qsv .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
if got, want := err.Error(), `^encoding video with ".*/test_data/mock_bin/ffmpeg" \[-i input -vcodec h264_qsv .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
||||||
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFfmpegWithCustomCOdec(t *testing.T) {
|
func TestFfmpegWithCustomCOdec(t *testing.T) {
|
||||||
doneCodec := test_env.SetEnv(utils.EnvVideoHardwareAcceleration.GetName(), "_custom")
|
doneCodec := test_utils.SetEnv(utils.EnvVideoHardwareAcceleration.GetName(), "_custom")
|
||||||
defer doneCodec()
|
defer doneCodec()
|
||||||
|
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
Ffmpeg = newFfmpegCli()
|
Ffmpeg = newFfmpegCli()
|
||||||
|
|
||||||
doneEnv := test_env.SetEnv("FAIL_WITH", "expect failure")
|
doneEnv := test_utils.SetEnv("FAIL_WITH", "expect failure")
|
||||||
defer doneEnv()
|
defer doneEnv()
|
||||||
|
|
||||||
err := Ffmpeg.EncodeMp4("input", "output")
|
err := Ffmpeg.EncodeMp4("input", "output")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
t.Fatalf("Ffmpeg.EncodeMp4(...) = nil, should be an error.")
|
||||||
}
|
}
|
||||||
if got, want := err.Error(), `^encoding video with ".*/testdata/bin/ffmpeg" \[-i input -vcodec custom .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
if got, want := err.Error(), `^encoding video with ".*/test_data/mock_bin/ffmpeg" \[-i input -vcodec custom .* output\] error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
||||||
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
t.Errorf("Ffmpeg.EncodeMp4(...) = %q, should be as reg pattern %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/test_utils/test_env"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMagickCliNotExist(t *testing.T) {
|
func TestMagickCliNotExist(t *testing.T) {
|
||||||
done := test_env.SetPathWithCurrent()
|
done := test_utils.SetPathWithCurrent()
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
Magick = newMagickCli()
|
Magick = newMagickCli()
|
||||||
@@ -28,10 +28,10 @@ func TestMagickCliNotExist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMagickCliIgnore(t *testing.T) {
|
func TestMagickCliIgnore(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
doneDisableRaw := test_env.SetEnv("PHOTOVIEW_DISABLE_RAW_PROCESSING", "true")
|
doneDisableRaw := test_utils.SetEnv("PHOTOVIEW_DISABLE_RAW_PROCESSING", "true")
|
||||||
defer doneDisableRaw()
|
defer doneDisableRaw()
|
||||||
|
|
||||||
Magick = newMagickCli()
|
Magick = newMagickCli()
|
||||||
@@ -50,10 +50,10 @@ func TestMagickCliIgnore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMagickCliVersionFail(t *testing.T) {
|
func TestMagickCliVersionFail(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
done := test_env.SetEnv("FAIL_WITH", "failure")
|
done := test_utils.SetEnv("FAIL_WITH", "failure")
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
Magick = newMagickCli()
|
Magick = newMagickCli()
|
||||||
@@ -72,7 +72,7 @@ func TestMagickCliVersionFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMagickCliFail(t *testing.T) {
|
func TestMagickCliFail(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
Magick = newMagickCli()
|
Magick = newMagickCli()
|
||||||
@@ -81,7 +81,7 @@ func TestMagickCliFail(t *testing.T) {
|
|||||||
t.Fatal("MagickCli should be installed")
|
t.Fatal("MagickCli should be installed")
|
||||||
}
|
}
|
||||||
|
|
||||||
done := test_env.SetEnv("FAIL_WITH", "failure")
|
done := test_utils.SetEnv("FAIL_WITH", "failure")
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
err := Magick.EncodeJpeg("input", "output", 70)
|
err := Magick.EncodeJpeg("input", "output", 70)
|
||||||
@@ -89,13 +89,13 @@ func TestMagickCliFail(t *testing.T) {
|
|||||||
t.Fatalf(`MagickCli.EncodeJpeg(...) = nil, should be an error.`)
|
t.Fatalf(`MagickCli.EncodeJpeg(...) = nil, should be an error.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, want := err.Error(), `^encoding image with ".*/testdata/bin/magick \[input -auto-orient -quality 70 output\]" error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
if got, want := err.Error(), `^encoding image with ".*/test_data/mock_bin/magick \[input -auto-orient -quality 70 output\]" error: .*$`; !regexp.MustCompile(want).MatchString(got) {
|
||||||
t.Errorf(`MagickCli.EncodeJpeg(...) = %q, should be matched with reg pattern %q`, got, want)
|
t.Errorf(`MagickCli.EncodeJpeg(...) = %q, should be matched with reg pattern %q`, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMagickCliSucceed(t *testing.T) {
|
func TestMagickCliSucceed(t *testing.T) {
|
||||||
donePath := test_env.SetPathWithCurrent(testdataBinPath)
|
donePath := test_utils.SetPathWithCurrent(testdataBinPath)
|
||||||
defer donePath()
|
defer donePath()
|
||||||
|
|
||||||
Magick = newMagickCli()
|
Magick = newMagickCli()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testDataPath = "./test_data"
|
const testDataPath = "./test_media/library"
|
||||||
|
|
||||||
func TestNewRootPath(t *testing.T) {
|
func TestNewRootPath(t *testing.T) {
|
||||||
db := test_utils.DatabaseTest(t)
|
db := test_utils.DatabaseTest(t)
|
||||||
@@ -29,7 +29,7 @@ func TestNewRootPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.NotNil(t, album)
|
assert.NotNil(t, album)
|
||||||
assert.Contains(t, album.Path, "/api/scanner/test_data")
|
assert.Contains(t, album.Path, "/api/scanner/test_media")
|
||||||
assert.NotEmpty(t, album.Owners)
|
assert.NotEmpty(t, album.Owners)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func TestNewRootPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.NotNil(t, album)
|
assert.NotNil(t, album)
|
||||||
assert.Contains(t, album.Path, "/api/scanner/test_data")
|
assert.Contains(t, album.Path, "/api/scanner/test_media")
|
||||||
|
|
||||||
ownerCount := db.Model(&album).Association("Owners").Count()
|
ownerCount := db.Model(&album).Association("Owners").Count()
|
||||||
assert.EqualValues(t, 2, ownerCount)
|
assert.EqualValues(t, 2, ownerCount)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/photoview/photoview/api/graphql/models"
|
"github.com/photoview/photoview/api/graphql/models"
|
||||||
"github.com/photoview/photoview/api/scanner/face_detection"
|
"github.com/photoview/photoview/api/scanner/face_detection"
|
||||||
"github.com/photoview/photoview/api/test_utils"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
|
scanner_utils "github.com/photoview/photoview/api/test_utils/scanner"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ func TestCleanupMedia(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testDir := t.TempDir()
|
testDir := t.TempDir()
|
||||||
assert.NoError(t, copy.Copy("../../test_data", testDir))
|
assert.NoError(t, copy.Copy("../../test_media/library", testDir))
|
||||||
|
|
||||||
countAllMedia := func() int {
|
countAllMedia := func() int {
|
||||||
var allMedia []*models.Media
|
var allMedia []*models.Media
|
||||||
@@ -79,31 +80,31 @@ func TestCleanupMedia(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Modify albums", func(t *testing.T) {
|
t.Run("Modify albums", func(t *testing.T) {
|
||||||
test_utils.RunScannerOnUser(t, db, user1)
|
scanner_utils.RunScannerOnUser(t, db, user1)
|
||||||
assert.Equal(t, 9, countAllMedia())
|
assert.Equal(t, 9, countAllMedia())
|
||||||
assert.Equal(t, 18, countAllMediaURLs())
|
assert.Equal(t, 18, countAllMediaURLs())
|
||||||
|
|
||||||
// move faces directory
|
// move faces directory
|
||||||
assert.NoError(t, os.Rename(path.Join(testDir, "faces"), path.Join(testDir, "faces_moved")))
|
assert.NoError(t, os.Rename(path.Join(testDir, "faces"), path.Join(testDir, "faces_moved")))
|
||||||
test_utils.RunScannerAll(t, db)
|
scanner_utils.RunScannerAll(t, db)
|
||||||
assert.Equal(t, 9, countAllMedia())
|
assert.Equal(t, 9, countAllMedia())
|
||||||
assert.Equal(t, 18, countAllMediaURLs())
|
assert.Equal(t, 18, countAllMediaURLs())
|
||||||
|
|
||||||
// remove faces_moved directory
|
// remove faces_moved directory
|
||||||
assert.NoError(t, os.RemoveAll(path.Join(testDir, "faces_moved")))
|
assert.NoError(t, os.RemoveAll(path.Join(testDir, "faces_moved")))
|
||||||
test_utils.RunScannerAll(t, db)
|
scanner_utils.RunScannerAll(t, db)
|
||||||
assert.Equal(t, 3, countAllMedia())
|
assert.Equal(t, 3, countAllMedia())
|
||||||
assert.Equal(t, 6, countAllMediaURLs())
|
assert.Equal(t, 6, countAllMediaURLs())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Modify images", func(t *testing.T) {
|
t.Run("Modify images", func(t *testing.T) {
|
||||||
assert.NoError(t, os.Rename(path.Join(testDir, "buttercup_close_summer_yellow.jpg"), path.Join(testDir, "yellow-flower.jpg")))
|
assert.NoError(t, os.Rename(path.Join(testDir, "buttercup_close_summer_yellow.jpg"), path.Join(testDir, "yellow-flower.jpg")))
|
||||||
test_utils.RunScannerAll(t, db)
|
scanner_utils.RunScannerAll(t, db)
|
||||||
assert.Equal(t, 3, countAllMedia())
|
assert.Equal(t, 3, countAllMedia())
|
||||||
assert.Equal(t, 6, countAllMediaURLs())
|
assert.Equal(t, 6, countAllMediaURLs())
|
||||||
|
|
||||||
assert.NoError(t, os.Remove(path.Join(testDir, "lilac_lilac_bush_lilac.jpg")))
|
assert.NoError(t, os.Remove(path.Join(testDir, "lilac_lilac_bush_lilac.jpg")))
|
||||||
test_utils.RunScannerAll(t, db)
|
scanner_utils.RunScannerAll(t, db)
|
||||||
assert.Equal(t, 2, countAllMedia())
|
assert.Equal(t, 2, countAllMedia())
|
||||||
assert.Equal(t, 4, countAllMediaURLs())
|
assert.Equal(t, 4, countAllMediaURLs())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/scanner/scanner_task"
|
"github.com/photoview/photoview/api/scanner/scanner_task"
|
||||||
"github.com/photoview/photoview/api/test_utils/test_env"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
"github.com/photoview/photoview/api/utils"
|
"github.com/photoview/photoview/api/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -69,11 +69,11 @@ func TestCounterpartFilesTaskMediaFound(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaPath := test_env.PathFromAPIRoot("scanner/test_data/fake_media")
|
mediaPath := test_utils.PathFromAPIRoot("scanner/test_media/fake_media")
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
done := test_env.SetEnv(string(utils.EnvDisableRawProcessing), fmt.Sprintf("%v", tc.disableRawProcessing))
|
done := test_utils.SetEnv(string(utils.EnvDisableRawProcessing), fmt.Sprintf("%v", tc.disableRawProcessing))
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
ctx := scanner_task.NewTaskContext(context.Background(), nil, nil, nil)
|
ctx := scanner_task.NewTaskContext(context.Background(), nil, nil, nil)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/photoview/photoview/api/graphql/models"
|
"github.com/photoview/photoview/api/graphql/models"
|
||||||
"github.com/photoview/photoview/api/scanner/face_detection"
|
"github.com/photoview/photoview/api/scanner/face_detection"
|
||||||
"github.com/photoview/photoview/api/test_utils"
|
"github.com/photoview/photoview/api/test_utils"
|
||||||
|
scanner_utils "github.com/photoview/photoview/api/test_utils/scanner"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ func TestFullScan(t *testing.T) {
|
|||||||
|
|
||||||
rootAlbum := models.Album{
|
rootAlbum := models.Album{
|
||||||
Title: "root album",
|
Title: "root album",
|
||||||
Path: "./test_data",
|
Path: "./test_media/library",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !assert.NoError(t, db.Save(&rootAlbum).Error) {
|
if !assert.NoError(t, db.Save(&rootAlbum).Error) {
|
||||||
@@ -43,7 +44,7 @@ func TestFullScan(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
test_utils.RunScannerOnUser(t, db, user)
|
scanner_utils.RunScannerOnUser(t, db, user)
|
||||||
|
|
||||||
var allMedia []*models.Media
|
var allMedia []*models.Media
|
||||||
if !assert.NoError(t, db.Find(&allMedia).Error) {
|
if !assert.NoError(t, db.Find(&allMedia).Error) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 229 KiB After Width: | Height: | Size: 229 KiB |
|
Before Width: | Height: | Size: 267 KiB After Width: | Height: | Size: 267 KiB |
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 171 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 236 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
BIN
api/scanner/test_media/real_media/avi.avi
Normal file
BIN
api/scanner/test_media/real_media/bmp.bmp
Normal file
|
After Width: | Height: | Size: 30 B |
5
api/scanner/test_media/real_media/file.pdf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
%PDF-1.
|
||||||
|
1 0 obj<</Pages 2 0 R>>endobj
|
||||||
|
2 0 obj<</Kids[3 0 R]/Count 1>>endobj
|
||||||
|
3 0 obj<</Parent 2 0 R>>endobj
|
||||||
|
trailer <</Root 1 0 R>>
|
||||||
BIN
api/scanner/test_media/real_media/gif.gif
Normal file
|
After Width: | Height: | Size: 14 B |
BIN
api/scanner/test_media/real_media/heif.heif
Normal file
BIN
api/scanner/test_media/real_media/jpeg.jpg
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
api/scanner/test_media/real_media/jpeg2000.jp2
Normal file
BIN
api/scanner/test_media/real_media/jpg_with_file.jpg
Normal file
|
After Width: | Height: | Size: 160 B |
5
api/scanner/test_media/real_media/jpg_with_file.pdf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
%PDF-1.
|
||||||
|
1 0 obj<</Pages 2 0 R>>endobj
|
||||||
|
2 0 obj<</Kids[3 0 R]/Count 1>>endobj
|
||||||
|
3 0 obj<</Parent 2 0 R>>endobj
|
||||||
|
trailer <</Root 1 0 R>>
|
||||||
BIN
api/scanner/test_media/real_media/mkv.mkv
Normal file
BIN
api/scanner/test_media/real_media/mp4.mp4
Normal file
BIN
api/scanner/test_media/real_media/mpeg.mpg
Normal file
BIN
api/scanner/test_media/real_media/ogg.ogg
Normal file
BIN
api/scanner/test_media/real_media/png.png
Normal file
|
After Width: | Height: | Size: 67 B |
BIN
api/scanner/test_media/real_media/quicktime.mov
Normal file
5
api/scanner/test_media/real_media/raw_with_file.pdf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
%PDF-1.
|
||||||
|
1 0 obj<</Pages 2 0 R>>endobj
|
||||||
|
2 0 obj<</Kids[3 0 R]/Count 1>>endobj
|
||||||
|
3 0 obj<</Parent 2 0 R>>endobj
|
||||||
|
trailer <</Root 1 0 R>>
|
||||||
BIN
api/scanner/test_media/real_media/raw_with_file.tiff
Normal file
BIN
api/scanner/test_media/real_media/raw_with_jpg.jpg
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
api/scanner/test_media/real_media/raw_with_jpg.tiff
Normal file
BIN
api/scanner/test_media/real_media/standalone_jpg.jpg
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
api/scanner/test_media/real_media/standalone_raw.tiff
Normal file
BIN
api/scanner/test_media/real_media/tiff.tiff
Normal file
BIN
api/scanner/test_media/real_media/webm.webm
Normal file
BIN
api/scanner/test_media/real_media/webp.webp
Normal file
|
After Width: | Height: | Size: 26 B |
BIN
api/scanner/test_media/real_media/wmv.wmv
Normal file
@@ -1,24 +1,12 @@
|
|||||||
package test_env
|
package test_utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type integration_options struct {
|
|
||||||
Database *bool
|
|
||||||
Filesystem *bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fake flags to be compatible with current test command.
|
|
||||||
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"),
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetPathWithCurrent(paths ...string) func() {
|
func SetPathWithCurrent(paths ...string) func() {
|
||||||
_, file, _, ok := runtime.Caller(1)
|
_, file, _, ok := runtime.Caller(1)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -57,5 +45,5 @@ func PathFromAPIRoot(rootRelatedPath string) string {
|
|||||||
|
|
||||||
base := filepath.Dir(file)
|
base := filepath.Dir(file)
|
||||||
|
|
||||||
return filepath.Join(base, "../..", rootRelatedPath)
|
return filepath.Join(base, "..", rootRelatedPath)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package test_env
|
package test_utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -20,7 +20,7 @@ func TestSetPathWithCurrent(t *testing.T) {
|
|||||||
defer testDone()
|
defer testDone()
|
||||||
|
|
||||||
path := os.Getenv("PATH")
|
path := os.Getenv("PATH")
|
||||||
if got, want := path, "api/test_utils/test_env/test"; !strings.HasSuffix(got, want) {
|
if got, want := path, "api/test_utils/test"; !strings.HasSuffix(got, want) {
|
||||||
t.Errorf("path = %q, want a suffix: %q", got, want)
|
t.Errorf("path = %q, want a suffix: %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package test_utils
|
package scanner_utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||