2020-05-18 22:18:58 +02:00
|
|
|
package entity
|
|
|
|
|
2020-07-10 15:06:37 +02:00
|
|
|
import (
|
2020-07-11 23:43:29 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-07-10 15:06:37 +02:00
|
|
|
"testing"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-07-10 15:06:37 +02:00
|
|
|
)
|
2020-05-18 22:18:58 +02:00
|
|
|
|
|
|
|
func TestPhoto_Yaml(t *testing.T) {
|
|
|
|
t.Run("create from fixture", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
m.PreloadFiles()
|
|
|
|
result, err := m.Yaml()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("YAML: %s", result)
|
|
|
|
})
|
|
|
|
}
|
2020-07-10 15:06:37 +02:00
|
|
|
|
|
|
|
func TestPhoto_SaveAsYaml(t *testing.T) {
|
|
|
|
t.Run("create from fixture", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
m.PreloadFiles()
|
|
|
|
|
2020-07-11 23:43:29 +02:00
|
|
|
fileName := filepath.Join(os.TempDir(), ".photoprism_test.yml")
|
|
|
|
|
|
|
|
if err := m.SaveAsYaml(fileName); err != nil {
|
2020-07-10 15:06:37 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-11 23:43:29 +02:00
|
|
|
if err := m.LoadFromYaml(fileName); err != nil {
|
2020-07-10 15:06:37 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-11 23:43:29 +02:00
|
|
|
if err := os.Remove(fileName); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-10 15:06:37 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_YamlFileName(t *testing.T) {
|
|
|
|
t.Run("create from fixture", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
m.PreloadFiles()
|
|
|
|
assert.Equal(t, "xxx/2790/02/yyy/Photo01.yml", m.YamlFileName("xxx", "yyy"))
|
|
|
|
|
2020-07-12 04:48:17 +02:00
|
|
|
if err := os.RemoveAll("xxx"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-10 15:06:37 +02:00
|
|
|
})
|
|
|
|
}
|