Tests: Add unit tests

This commit is contained in:
theresa 2021-08-31 17:18:48 +02:00
parent bf2d4ceb43
commit e5bfa6d78e
3 changed files with 114 additions and 8 deletions

View file

@ -15,6 +15,14 @@ func TestLikeAny(t *testing.T) {
assert.Equal(t, "k.keyword LIKE 'json%' OR k.keyword LIKE 'usa'", w[1])
}
})
t.Run(" exact and_or_search", func(t *testing.T) {
if w := LikeAny("k.keyword", "table spoon & usa | img json", true, true); len(w) != 2 {
t.Fatal("two where conditions expected")
} else {
assert.Equal(t, "k.keyword LIKE 'spoon' OR k.keyword LIKE 'table'", w[0])
assert.Equal(t, "k.keyword LIKE 'json' OR k.keyword LIKE 'usa'", w[1])
}
})
t.Run("and_or_search_en", func(t *testing.T) {
if w := LikeAny("k.keyword", "table spoon and usa or img json", true, false); len(w) != 2 {
t.Fatal("two where conditions expected")
@ -125,6 +133,14 @@ func TestLikeAll(t *testing.T) {
t.Fatal("two where conditions expected")
}
})
t.Run("string empty", func(t *testing.T) {
w := LikeAll("k.keyword", "", true, true)
assert.Empty(t, w)
})
t.Run("0 words", func(t *testing.T) {
w := LikeAll("k.keyword", "ab", true, true)
assert.Empty(t, w)
})
}
func TestLikeAllKeywords(t *testing.T) {
@ -164,6 +180,14 @@ func TestLikeAllNames(t *testing.T) {
t.Fatal("4 where conditions expected")
}
})
t.Run("string empty", func(t *testing.T) {
w := LikeAllNames("k.name", "")
assert.Empty(t, w)
})
t.Run("0 words", func(t *testing.T) {
w := LikeAllNames("k.name", "a")
assert.Empty(t, w)
})
}
func TestAnySlug(t *testing.T) {

View file

@ -802,4 +802,76 @@ func TestPhotoSearch(t *testing.T) {
assert.GreaterOrEqual(t, len(photos), 3)
})
t.Run("faces:yes", func(t *testing.T) {
var f form.PhotoSearch
f.Faces = "Yes"
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 3)
})
t.Run("faces:no", func(t *testing.T) {
var f form.PhotoSearch
f.Faces = "No"
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 9)
})
t.Run("faces:2", func(t *testing.T) {
var f form.PhotoSearch
f.Faces = "2"
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 1)
})
t.Run("filename", func(t *testing.T) {
var f form.PhotoSearch
f.Filename = "1990/04/Quality1FavoriteTrue.jpg"
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 1)
})
t.Run("original name or original name", func(t *testing.T) {
var f form.PhotoSearch
f.Original = "my-videos/IMG_88888" + "|" + "Vacation/exampleFileNameOriginal"
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 2)
})
t.Run("Stack", func(t *testing.T) {
var f form.PhotoSearch
f.Stack = true
photos, _, err := PhotoSearch(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(photos), 2)
})
}

View file

@ -55,13 +55,23 @@ func TestCreateMarkerSubjects(t *testing.T) {
}
func TestSearchSubjectUIDs(t *testing.T) {
result, names, remaining := SearchSubjectUIDs("john & his | cats")
t.Run("john & his | cats", func(t *testing.T) {
result, names, remaining := SearchSubjectUIDs("john & his | cats")
if len(result) != 1 {
t.Fatal("expected one result")
} else {
assert.Equal(t, "jqu0xs11qekk9jx8", result[0])
assert.Equal(t, "his | cats", remaining)
assert.Equal(t, "John Doe", strings.Join(names, ", "))
}
if len(result) != 1 {
t.Fatal("expected one result")
} else {
assert.Equal(t, "jqu0xs11qekk9jx8", result[0])
assert.Equal(t, "his | cats", remaining)
assert.Equal(t, "John Doe", strings.Join(names, ", "))
}
})
t.Run("xxx", func(t *testing.T) {
result, _, _ := SearchSubjectUIDs("xxx")
assert.Empty(t, result)
})
t.Run("empty string", func(t *testing.T) {
result, _, _ := SearchSubjectUIDs("")
assert.Empty(t, result)
})
}