photoprism/internal/entity/photo_yaml_test.go
Michael Mayer 00e334657a Photo: Set defaults for PlaceID, GeoID, CameraID and LensID
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-07-12 04:48:17 +02:00

55 lines
1.1 KiB
Go

package entity
import (
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)
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)
})
}
func TestPhoto_SaveAsYaml(t *testing.T) {
t.Run("create from fixture", func(t *testing.T) {
m := PhotoFixtures.Get("Photo01")
m.PreloadFiles()
fileName := filepath.Join(os.TempDir(), ".photoprism_test.yml")
if err := m.SaveAsYaml(fileName); err != nil {
t.Fatal(err)
}
if err := m.LoadFromYaml(fileName); err != nil {
t.Fatal(err)
}
if err := os.Remove(fileName); err != nil {
t.Fatal(err)
}
})
}
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"))
if err := os.RemoveAll("xxx"); err != nil {
t.Fatal(err)
}
})
}