photoprism/internal/query/files_test.go

123 lines
2.5 KiB
Go
Raw Normal View History

2020-01-28 20:59:26 +01:00
package query
import (
2020-05-13 10:16:12 +02:00
"github.com/photoprism/photoprism/internal/entity"
2020-01-28 20:59:26 +01:00
"testing"
"github.com/stretchr/testify/assert"
2020-01-28 20:59:26 +01:00
)
func TestExistingFiles(t *testing.T) {
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
files, err := ExistingFiles(1000, 0, "/")
t.Logf("files: %+v", files)
2020-01-28 20:59:26 +01:00
2020-05-13 10:16:12 +02:00
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 5, len(files))
2020-01-28 20:59:26 +01:00
})
2020-05-13 10:16:12 +02:00
t.Run("search for files path", func(t *testing.T) {
files, err := ExistingFiles(1000, 0, "Photos")
t.Logf("files: %+v", files)
if err != nil {
t.Fatal(err)
}
assert.Empty(t, files)
})
2020-01-28 20:59:26 +01:00
}
func TestFilesByUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
files, err := FilesByUUID([]string{"ft8es39w45bnlqdw"}, 100, 0)
2020-01-28 20:59:26 +01:00
2020-05-13 10:16:12 +02:00
if err != nil {
t.Fatal(err)
}
2020-01-28 20:59:26 +01:00
assert.Equal(t, 1, len(files))
assert.Equal(t, "exampleFileName.jpg", files[0].FileName)
})
2020-05-13 10:16:12 +02:00
t.Run("no files found", func(t *testing.T) {
files, err := FilesByUUID([]string{"ft8es39w45bnlxxx"}, 100, 0)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 0, len(files))
})
2020-01-28 20:59:26 +01:00
}
func TestFileByPhotoUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := FileByPhotoUUID("pt9jtdre2lvl0yh8")
2020-01-28 20:59:26 +01:00
2020-05-13 10:16:12 +02:00
if err != nil {
t.Fatal(err)
}
2020-01-28 20:59:26 +01:00
assert.Equal(t, "exampleDNGFile.dng", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := FileByPhotoUUID("111")
2020-01-28 20:59:26 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestFileByUUID(t *testing.T) {
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := FileByUUID("ft8es39w45bnlqdw")
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 := 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 TestFileByHash(t *testing.T) {
2020-01-28 20:59:26 +01:00
t.Run("files found", func(t *testing.T) {
file, err := FileByHash("2cad9168fa6acc5c5c2965ddf6ec465ca42fd818")
2020-01-28 20:59:26 +01:00
2020-05-13 10:16:12 +02:00
if err != nil {
t.Fatal(err)
}
2020-01-28 20:59:26 +01:00
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := FileByHash("111")
2020-01-28 20:59:26 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
2020-05-13 10:16:12 +02:00
func TestSetPhotoPrimary(t *testing.T) {
assert.Equal(t, false, entity.FileFixturesExampleXMP.FilePrimary)
err := SetPhotoPrimary("pt9jtdre2lvl0yh8", "ft1es39w45bnlqdw")
if err != nil {
t.Fatal(err)
}
//TODO How to assert
//assert.Equal(t, true, entity.FileFixturesExampleXMP.FilePrimary)
}