photoprism/internal/query/file_test.go

103 lines
2 KiB
Go
Raw Normal View History

2020-01-28 20:59:26 +01:00
package query
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/photoprism/photoprism/internal/config"
)
func TestQuery_Files(t *testing.T) {
2020-01-28 20:59:26 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
files, err := search.Files(1000, 0)
2020-01-28 20:59:26 +01:00
assert.Nil(t, err)
2020-01-28 22:16:59 +01:00
assert.Equal(t, 5, len(files))
2020-01-28 20:59:26 +01:00
})
}
func TestQuery_FilesByUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
files, err := search.FilesByUUID([]string{"654"}, 100, 0)
2020-01-28 20:59:26 +01:00
assert.Nil(t, err)
assert.Equal(t, 1, len(files))
assert.Equal(t, "exampleFileName.jpg", files[0].FileName)
})
}
func TestQuery_FileByPhotoUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := search.FileByPhotoUUID("655")
2020-01-28 20:59:26 +01:00
assert.Nil(t, err)
assert.Equal(t, "exampleDNGFile.dng", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := search.FileByPhotoUUID("111")
2020-01-28 20:59:26 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestQuery_FileByUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := search.FileByUUID("fq8es39w45bnlqdw")
2020-01-28 20:59:26 +01:00
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "exampleFileName.jpg", file.FileName)
2020-01-28 20:59:26 +01:00
})
t.Run("no files found", func(t *testing.T) {
file, err := search.FileByUUID("111")
if err == nil {
t.Fatal("error expected")
}
2020-01-28 20:59:26 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestQuery_FileByHash(t *testing.T) {
2020-01-28 20:59:26 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := search.FileByHash("123xxx")
2020-01-28 20:59:26 +01:00
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := search.FileByHash("111")
2020-01-28 20:59:26 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}