2021-08-14 20:48:38 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-08-24 20:15:36 +02:00
|
|
|
"time"
|
2021-08-14 20:48:38 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-01 20:46:15 +02:00
|
|
|
func TestMarkerByUID(t *testing.T) {
|
|
|
|
t.Run("Found", func(t *testing.T) {
|
|
|
|
if m, err := MarkerByUID("mt9k3pw1wowuy888"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if m == nil {
|
|
|
|
t.Fatal("result is nil")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("NotFound", func(t *testing.T) {
|
|
|
|
if _, err := MarkerByUID("mt9k3aa1wowuy888"); err == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-14 20:48:38 +02:00
|
|
|
func TestMarkers(t *testing.T) {
|
2021-08-24 20:15:36 +02:00
|
|
|
t.Run("find umatched", func(t *testing.T) {
|
2021-08-29 13:26:05 +02:00
|
|
|
results, err := Markers(3, 0, entity.MarkerFace, false, false, entity.TimeStamp())
|
2021-08-24 20:15:36 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, len(results), 1)
|
|
|
|
|
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Marker{}, val)
|
|
|
|
}
|
|
|
|
})
|
2021-08-19 21:12:38 +02:00
|
|
|
t.Run("find all", func(t *testing.T) {
|
2021-08-24 20:15:36 +02:00
|
|
|
results, err := Markers(3, 0, entity.MarkerFace, false, false, time.Time{})
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-19 21:12:38 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.GreaterOrEqual(t, len(results), 1)
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-19 21:12:38 +02:00
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Marker{}, val)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("find embeddings", func(t *testing.T) {
|
2021-08-24 20:15:36 +02:00
|
|
|
results, err := Markers(3, 0, entity.MarkerFace, true, false, time.Time{})
|
2021-08-19 21:12:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, len(results), 1)
|
|
|
|
|
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Marker{}, val)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("find false", func(t *testing.T) {
|
2021-08-24 20:15:36 +02:00
|
|
|
results, err := Markers(3, 0, entity.MarkerFace, false, true, time.Time{})
|
2021-08-19 21:12:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-30 13:40:14 +02:00
|
|
|
assert.Equal(t, 3, len(results))
|
2021-08-19 21:12:38 +02:00
|
|
|
})
|
2021-08-14 20:48:38 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
func TestUnmatchedFaceMarkers(t *testing.T) {
|
|
|
|
t.Run("all", func(t *testing.T) {
|
|
|
|
results, err := UnmatchedFaceMarkers(3, 0, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 3, len(results))
|
|
|
|
})
|
|
|
|
t.Run("before", func(t *testing.T) {
|
|
|
|
results, err := UnmatchedFaceMarkers(3, 0, entity.TimePointer())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 3, len(results))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFaceMarkers(t *testing.T) {
|
|
|
|
t.Run("all", func(t *testing.T) {
|
|
|
|
results, err := FaceMarkers(3, 0)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 3, len(results))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-14 20:48:38 +02:00
|
|
|
func TestEmbeddings(t *testing.T) {
|
2021-08-29 13:26:05 +02:00
|
|
|
t.Run("all", func(t *testing.T) {
|
|
|
|
results, err := Embeddings(false, false, 0, 0)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, len(results), 1)
|
|
|
|
|
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Embedding{}, val)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("size", func(t *testing.T) {
|
|
|
|
results, err := Embeddings(false, false, 230, 0)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-30 17:20:39 +02:00
|
|
|
assert.Equal(t, len(results), 8)
|
2021-08-29 13:26:05 +02:00
|
|
|
|
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Embedding{}, val)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("score", func(t *testing.T) {
|
|
|
|
results, err := Embeddings(false, false, 0, 50)
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
assert.GreaterOrEqual(t, len(results), 1)
|
2021-08-14 20:48:38 +02:00
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
for _, val := range results {
|
|
|
|
assert.IsType(t, entity.Embedding{}, val)
|
|
|
|
}
|
|
|
|
})
|
2021-08-14 20:48:38 +02:00
|
|
|
}
|
|
|
|
|
2021-08-23 16:22:01 +02:00
|
|
|
func TestRemoveInvalidMarkerReferences(t *testing.T) {
|
|
|
|
affected, err := RemoveInvalidMarkerReferences()
|
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.GreaterOrEqual(t, affected, int64(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveNonExistentMarkerFaces(t *testing.T) {
|
|
|
|
affected, err := RemoveNonExistentMarkerFaces()
|
|
|
|
|
2021-08-23 16:22:01 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.GreaterOrEqual(t, affected, int64(1))
|
2021-08-19 21:12:38 +02:00
|
|
|
}
|
2021-08-24 20:15:36 +02:00
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
func TestRemoveNonExistentMarkerSubjects(t *testing.T) {
|
|
|
|
affected, err := RemoveNonExistentMarkerSubjects()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.GreaterOrEqual(t, affected, int64(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFixMarkerReferences(t *testing.T) {
|
|
|
|
affected, err := FixMarkerReferences()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.GreaterOrEqual(t, affected, int64(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarkersWithNonExistentReferences(t *testing.T) {
|
|
|
|
f, s, err := MarkersWithNonExistentReferences()
|
2021-08-28 15:26:26 +02:00
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, len(f), 0)
|
|
|
|
assert.GreaterOrEqual(t, len(s), 0)
|
|
|
|
}
|
|
|
|
|
2021-08-28 17:27:37 +02:00
|
|
|
func TestMarkersWithSubjectConflict(t *testing.T) {
|
|
|
|
m, err := MarkersWithSubjectConflict()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, len(m), 0)
|
|
|
|
}
|
|
|
|
|
2021-08-24 20:15:36 +02:00
|
|
|
func TestCountUnmatchedFaceMarkers(t *testing.T) {
|
2021-08-29 13:26:05 +02:00
|
|
|
n := CountUnmatchedFaceMarkers()
|
2021-08-24 20:15:36 +02:00
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
assert.GreaterOrEqual(t, n, 1)
|
2021-08-24 20:15:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountMarkers(t *testing.T) {
|
|
|
|
n := CountMarkers(entity.MarkerFace)
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, n, 1)
|
|
|
|
}
|