Backend: Add unit tests
This commit is contained in:
parent
f38434dfb0
commit
ce4960e2b8
2 changed files with 115 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package photoprism
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/classify"
|
||||
|
@ -32,3 +33,22 @@ func TestIndex_Start(t *testing.T) {
|
|||
|
||||
ind.Start(indexOpt)
|
||||
}
|
||||
|
||||
func TestIndex_File(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
conf := config.TestConfig()
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
|
||||
tf := classify.New(conf.AssetsPath(), conf.TensorFlowOff())
|
||||
nd := nsfw.New(conf.NSFWModelPath())
|
||||
convert := NewConvert(conf)
|
||||
|
||||
ind := NewIndex(conf, tf, nd, convert)
|
||||
|
||||
err := ind.File("xxx")
|
||||
assert.Equal(t, IndexFailed, err.Status)
|
||||
}
|
||||
|
|
95
internal/photoprism/related_test.go
Normal file
95
internal/photoprism/related_test.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
package photoprism
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRelatedFiles_ContainsJpeg(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
t.Run("true", func(t *testing.T) {
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/telegram_2020-01-30_09-57-18.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mediaFile2, err2 := NewMediaFile(conf.ExamplesPath() + "/Screenshot 2019-05-21 at 10.45.52.png")
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
mediaFile3, err3 := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
if err3 != nil {
|
||||
t.Fatal(err3)
|
||||
}
|
||||
relatedFiles := RelatedFiles{
|
||||
Files: MediaFiles{mediaFile, mediaFile2},
|
||||
Main: mediaFile3,
|
||||
}
|
||||
assert.True(t, relatedFiles.ContainsJpeg())
|
||||
})
|
||||
t.Run("false", func(t *testing.T) {
|
||||
mediaFile3, err3 := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
if err3 != nil {
|
||||
t.Fatal(err3)
|
||||
}
|
||||
mediaFile2, err2 := NewMediaFile(conf.ExamplesPath() + "/Screenshot 2019-05-21 at 10.45.52.png")
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
relatedFiles := RelatedFiles{
|
||||
Files: MediaFiles{mediaFile3, mediaFile2},
|
||||
Main: nil,
|
||||
}
|
||||
assert.False(t, relatedFiles.ContainsJpeg())
|
||||
})
|
||||
}
|
||||
|
||||
func TestRelatedFiles_String(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
t.Run("true", func(t *testing.T) {
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/telegram_2020-01-30_09-57-18.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mediaFile2, err2 := NewMediaFile(conf.ExamplesPath() + "/Screenshot 2019-05-21 at 10.45.52.png")
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
mediaFile3, err3 := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
if err3 != nil {
|
||||
t.Fatal(err3)
|
||||
}
|
||||
relatedFiles := RelatedFiles{
|
||||
Files: MediaFiles{mediaFile, mediaFile2},
|
||||
Main: mediaFile3,
|
||||
}
|
||||
assert.Equal(t, "telegram_2020-01-30_09-57-18.jpg, Screenshot 2019-05-21 at 10.45.52.png", relatedFiles.String())
|
||||
})
|
||||
}
|
||||
|
||||
func TestRelatedFiles_Len(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
t.Run("true", func(t *testing.T) {
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/telegram_2020-01-30_09-57-18.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mediaFile2, err2 := NewMediaFile(conf.ExamplesPath() + "/Screenshot 2019-05-21 at 10.45.52.png")
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
mediaFile3, err3 := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
if err3 != nil {
|
||||
t.Fatal(err3)
|
||||
}
|
||||
relatedFiles := RelatedFiles{
|
||||
Files: MediaFiles{mediaFile, mediaFile2},
|
||||
Main: mediaFile3,
|
||||
}
|
||||
assert.Equal(t, 2, relatedFiles.Len())
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue