photoprism/internal/entity/camera_test.go

152 lines
3.6 KiB
Go
Raw Normal View History

package entity
import (
2019-07-16 12:36:30 +02:00
"testing"
"github.com/stretchr/testify/assert"
)
func TestFirstOrCreateCamera(t *testing.T) {
t.Run("UnknownCamera", func(t *testing.T) {
m := UnknownCamera
assert.Equal(t, uint(1), m.ID)
assert.Equal(t, UnknownID, m.CameraSlug)
result := FirstOrCreateCamera(&m)
if result == nil {
t.Fatal("result should not be nil")
}
assert.Equal(t, uint(1), m.ID)
assert.Equal(t, UnknownID, m.CameraSlug)
assert.Equal(t, uint(1), result.ID)
assert.Equal(t, UnknownID, result.CameraSlug)
})
t.Run("existing camera", func(t *testing.T) {
camera := NewCamera("Apple", "iPhone SE")
result := FirstOrCreateCamera(camera)
if result == nil {
t.Fatal("result should not be nil")
}
assert.GreaterOrEqual(t, result.ID, uint(1))
})
t.Run("not existing camera", func(t *testing.T) {
camera := &Camera{ID: 10000000, CameraSlug: "camera-slug"}
result := FirstOrCreateCamera(camera)
if result == nil {
t.Fatal("result should not be nil")
}
assert.GreaterOrEqual(t, result.ID, uint(1))
})
}
func TestNewCamera(t *testing.T) {
t.Run("Unknown", func(t *testing.T) {
camera := NewCamera("", "")
2019-07-16 12:36:30 +02:00
assert.Equal(t, &UnknownCamera, camera)
2019-07-16 12:36:30 +02:00
})
t.Run("CanonEOS6D", func(t *testing.T) {
camera := NewCamera("Canon", "EOS 6D")
2019-07-16 12:36:30 +02:00
expected := &Camera{
CameraSlug: "canon-eos-6d",
CameraName: "Canon EOS 6D",
CameraMake: "Canon",
CameraModel: "EOS 6D",
2019-07-16 12:36:30 +02:00
}
2019-07-16 12:36:30 +02:00
assert.Equal(t, expected, camera)
})
t.Run("PanasonicLumix", func(t *testing.T) {
camera := NewCamera("Panasonic", "Panasonic Lumix")
2019-07-16 12:36:30 +02:00
expected := &Camera{
CameraSlug: "panasonic-lumix",
CameraName: "Panasonic Lumix",
CameraMake: "Panasonic",
CameraModel: "Lumix",
2019-07-16 12:36:30 +02:00
}
2019-07-16 12:36:30 +02:00
assert.Equal(t, expected, camera)
})
t.Run("TG4", func(t *testing.T) {
camera := NewCamera("", "TG-4")
2019-07-16 12:36:30 +02:00
expected := &Camera{
CameraSlug: "tg-4",
CameraName: "TG-4",
CameraMake: "",
CameraModel: "TG-4",
2019-07-16 12:36:30 +02:00
}
2019-07-16 12:36:30 +02:00
assert.Equal(t, expected, camera)
})
t.Run("Olympus", func(t *testing.T) {
camera := NewCamera("OLYMPUS OPTICAL CO.,LTD", "")
assert.Equal(t, "olympus", camera.CameraSlug)
assert.Equal(t, "Olympus", camera.CameraName)
assert.Equal(t, "Olympus", camera.CameraMake)
assert.Equal(t, "", camera.CameraModel)
})
t.Run("HuaweiP30", func(t *testing.T) {
camera := NewCamera("Huawei", "ELE-AL00")
assert.Equal(t, "huawei-p30", camera.CameraSlug)
assert.Equal(t, "HUAWEI P30", camera.CameraName)
assert.Equal(t, "HUAWEI", camera.CameraMake)
assert.Equal(t, "P30", camera.CameraModel)
})
2019-07-16 12:36:30 +02:00
}
func TestCamera_String(t *testing.T) {
t.Run("Unknown", func(t *testing.T) {
camera := NewCamera("", "")
2019-07-16 12:36:30 +02:00
cameraString := camera.String()
assert.Equal(t, "Unknown", cameraString)
2019-07-16 12:36:30 +02:00
})
t.Run("Nikon", func(t *testing.T) {
camera := NewCamera("Nikon", "foo")
2019-07-16 12:36:30 +02:00
cameraString := camera.String()
assert.Equal(t, "'NIKON foo'", cameraString)
2019-07-16 12:36:30 +02:00
})
t.Run("Foo", func(t *testing.T) {
camera := NewCamera("", "Foo")
2020-05-07 17:29:35 +02:00
cameraString := camera.String()
assert.Equal(t, "Foo", cameraString)
2020-05-07 17:29:35 +02:00
})
t.Run("Test", func(t *testing.T) {
camera := NewCamera("test", "")
2019-07-16 12:36:30 +02:00
cameraString := camera.String()
assert.Equal(t, "test", cameraString)
2019-07-16 12:36:30 +02:00
})
}
func TestCamera_Scanner(t *testing.T) {
t.Run("Unknown", func(t *testing.T) {
camera := NewCamera("", "")
assert.False(t, camera.Scanner())
})
t.Run("Foo", func(t *testing.T) {
camera := NewCamera("foo", "")
assert.False(t, camera.Scanner())
})
t.Run("NikonFoo", func(t *testing.T) {
camera := NewCamera("Nikon", "Foo")
assert.False(t, camera.Scanner())
})
t.Run("MSScanner", func(t *testing.T) {
camera := NewCamera("", "MS Scanner")
assert.True(t, camera.Scanner())
})
}