Backend: Add tests to internal/photoprism

This commit is contained in:
Theresa Gresch 2020-04-29 14:09:44 +02:00
parent 190333f4f5
commit 426e5a9f9c
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package photoprism
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestNonCanonical(t *testing.T) {
t.Run("short", func(t *testing.T) {
assert.Equal(t, true, NonCanonical("short"))
})
t.Run("short_", func(t *testing.T) {
assert.Equal(t, true, NonCanonical("short_"))
})
t.Run("short?", func(t *testing.T) {
assert.Equal(t, true, NonCanonical("short?"))
})
t.Run("short/test_test_test1234", func(t *testing.T) {
assert.Equal(t, false, NonCanonical("hort/test_test_test12345"))
})
}
func TestCanonicalName(t *testing.T) {
date := time.Date(
2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
assert.Equal(t, "20091117_203458_ERROR000", CanonicalName(date, "123"))
assert.Equal(t, "20091117_203458_12345678", CanonicalName(date, "12345678"))
}

View file

@ -0,0 +1,24 @@
package photoprism
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestImportOptionsCopy(t *testing.T) {
result := ImportOptionsCopy("xxx")
assert.Equal(t, "xxx", result.Path)
assert.Equal(t, false, result.Move)
assert.Equal(t, false, result.RemoveDotFiles)
assert.Equal(t, false, result.RemoveExistingFiles)
assert.Equal(t, false, result.RemoveEmptyDirectories)
}
func TestImportOptionsMove(t *testing.T) {
result := ImportOptionsMove("xxx")
assert.Equal(t, "xxx", result.Path)
assert.Equal(t, true, result.Move)
assert.Equal(t, true, result.RemoveDotFiles)
assert.Equal(t, true, result.RemoveExistingFiles)
assert.Equal(t, true, result.RemoveEmptyDirectories)
}