2020-05-10 19:43:49 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLabelBySlug(t *testing.T) {
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("file found", func(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
label, err := LabelBySlug("flower")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Flower", label.LabelName)
|
|
|
|
})
|
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("no file found", func(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
label, err := LabelBySlug("111")
|
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
assert.Empty(t, label.ID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func TestLabelByUID(t *testing.T) {
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("file found", func(t *testing.T) {
|
2020-05-23 20:58:58 +02:00
|
|
|
label, err := LabelByUID("lt9k3pw1wowuy3c5")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "COW", label.LabelName)
|
|
|
|
})
|
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("no file found", func(t *testing.T) {
|
2020-05-23 20:58:58 +02:00
|
|
|
label, err := LabelByUID("111")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
assert.Empty(t, label.ID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLabelThumbBySlug(t *testing.T) {
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("file found", func(t *testing.T) {
|
2020-05-25 19:10:44 +02:00
|
|
|
file, err := LabelThumbBySlug("cow")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-16 17:15:06 +02:00
|
|
|
assert.Equal(t, "1990/04/bridge2.jpg", file.FileName)
|
2020-05-10 19:43:49 +02:00
|
|
|
})
|
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("no file found", func(t *testing.T) {
|
2020-05-25 19:10:44 +02:00
|
|
|
file, err := LabelThumbBySlug("no-jpeg")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("did not expect to find file: %+v", file)
|
|
|
|
}
|
2020-05-10 19:43:49 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func TestLabelThumbByUID(t *testing.T) {
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("file found", func(t *testing.T) {
|
2020-05-25 19:10:44 +02:00
|
|
|
file, err := LabelThumbByUID("lt9k3pw1wowuy3c5")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-16 17:15:06 +02:00
|
|
|
assert.Equal(t, "1990/04/bridge2.jpg", file.FileName)
|
2020-05-10 19:43:49 +02:00
|
|
|
})
|
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("no file found", func(t *testing.T) {
|
2020-05-23 20:58:58 +02:00
|
|
|
file, err := LabelThumbByUID("14")
|
2020-05-10 19:43:49 +02:00
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|
2020-05-13 11:57:54 +02:00
|
|
|
|
|
|
|
func TestPhotoLabel(t *testing.T) {
|
|
|
|
t.Run("photo label found", func(t *testing.T) {
|
|
|
|
r, err := PhotoLabel(uint(1000000), uint(1000001))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 38, r.Uncertainty)
|
|
|
|
})
|
|
|
|
t.Run("no photo label found", func(t *testing.T) {
|
|
|
|
r, err := PhotoLabel(uint(1000000), uint(1000003))
|
|
|
|
assert.Equal(t, "record not found", err.Error())
|
|
|
|
t.Log(r)
|
|
|
|
})
|
|
|
|
}
|