2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-05-03 18:57:28 +02:00
|
|
|
|
|
|
|
import (
|
2019-07-16 12:36:30 +02:00
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-05-03 18:57:28 +02:00
|
|
|
)
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
func TestFirstOrCreateCamera(t *testing.T) {
|
2021-11-25 12:48:07 +01:00
|
|
|
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)
|
|
|
|
})
|
2020-07-08 18:09:18 +02:00
|
|
|
t.Run("existing camera", func(t *testing.T) {
|
2023-10-13 11:35:43 +02:00
|
|
|
camera := NewCamera("Apple", "iPhone SE")
|
2020-05-24 22:16:06 +02:00
|
|
|
|
|
|
|
result := FirstOrCreateCamera(camera)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:36:06 +02:00
|
|
|
assert.GreaterOrEqual(t, result.ID, uint(1))
|
|
|
|
})
|
2020-07-08 18:09:18 +02:00
|
|
|
t.Run("not existing camera", func(t *testing.T) {
|
2020-07-08 17:36:06 +02:00
|
|
|
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))
|
|
|
|
})
|
2020-04-30 20:07:03 +02:00
|
|
|
}
|
|
|
|
|
2019-05-03 18:57:28 +02:00
|
|
|
func TestNewCamera(t *testing.T) {
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Unknown", func(t *testing.T) {
|
2020-05-29 18:04:30 +02:00
|
|
|
camera := NewCamera("", "")
|
2019-07-16 12:36:30 +02:00
|
|
|
|
2020-04-25 14:22:47 +02:00
|
|
|
assert.Equal(t, &UnknownCamera, camera)
|
2019-07-16 12:36:30 +02:00
|
|
|
})
|
2023-10-13 11:35:43 +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",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "Canon EOS 6D",
|
|
|
|
CameraMake: "Canon",
|
|
|
|
CameraModel: "EOS 6D",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
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",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "Panasonic Lumix",
|
|
|
|
CameraMake: "Panasonic",
|
|
|
|
CameraModel: "Lumix",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("TG4", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "TG-4")
|
2019-07-16 12:36:30 +02:00
|
|
|
|
|
|
|
expected := &Camera{
|
|
|
|
CameraSlug: "tg-4",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "TG-4",
|
|
|
|
CameraMake: "",
|
|
|
|
CameraModel: "TG-4",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Olympus", func(t *testing.T) {
|
|
|
|
camera := NewCamera("OLYMPUS OPTICAL CO.,LTD", "")
|
2020-05-29 18:04:30 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "olympus", camera.CameraSlug)
|
|
|
|
assert.Equal(t, "Olympus", camera.CameraName)
|
|
|
|
assert.Equal(t, "Olympus", camera.CameraMake)
|
|
|
|
assert.Equal(t, "", camera.CameraModel)
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("HuaweiP30", func(t *testing.T) {
|
|
|
|
camera := NewCamera("Huawei", "ELE-AL00")
|
2020-05-29 18:04:30 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "huawei-p30", camera.CameraSlug)
|
2023-10-06 02:22:48 +02:00
|
|
|
assert.Equal(t, "HUAWEI P30", camera.CameraName)
|
|
|
|
assert.Equal(t, "HUAWEI", camera.CameraMake)
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Equal(t, "P30", camera.CameraModel)
|
|
|
|
})
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCamera_String(t *testing.T) {
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Unknown", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "")
|
2019-07-16 12:36:30 +02:00
|
|
|
cameraString := camera.String()
|
2023-10-13 11:35:43 +02:00
|
|
|
assert.Equal(t, "Unknown", cameraString)
|
2019-07-16 12:36:30 +02:00
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Nikon", func(t *testing.T) {
|
|
|
|
camera := NewCamera("Nikon", "foo")
|
2019-07-16 12:36:30 +02:00
|
|
|
cameraString := camera.String()
|
2023-10-13 11:35:43 +02:00
|
|
|
assert.Equal(t, "'NIKON foo'", cameraString)
|
2019-07-16 12:36:30 +02:00
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Foo", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "Foo")
|
2020-05-07 17:29:35 +02:00
|
|
|
cameraString := camera.String()
|
2023-10-13 11:35:43 +02:00
|
|
|
assert.Equal(t, "Foo", cameraString)
|
2020-05-07 17:29:35 +02:00
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Test", func(t *testing.T) {
|
|
|
|
camera := NewCamera("test", "")
|
2019-07-16 12:36:30 +02:00
|
|
|
cameraString := camera.String()
|
2023-10-13 11:35:43 +02:00
|
|
|
assert.Equal(t, "test", cameraString)
|
2019-07-16 12:36:30 +02:00
|
|
|
})
|
2019-05-03 18:57:28 +02:00
|
|
|
}
|
2023-02-22 16:21:26 +01:00
|
|
|
|
|
|
|
func TestCamera_Scanner(t *testing.T) {
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Unknown", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "")
|
2023-02-22 16:21:26 +01:00
|
|
|
assert.False(t, camera.Scanner())
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("Foo", func(t *testing.T) {
|
|
|
|
camera := NewCamera("foo", "")
|
2023-02-22 16:21:26 +01:00
|
|
|
assert.False(t, camera.Scanner())
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("NikonFoo", func(t *testing.T) {
|
|
|
|
camera := NewCamera("Nikon", "Foo")
|
2023-02-22 16:21:26 +01:00
|
|
|
assert.False(t, camera.Scanner())
|
|
|
|
})
|
2023-10-13 11:35:43 +02:00
|
|
|
t.Run("MSScanner", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "MS Scanner")
|
|
|
|
assert.True(t, camera.Scanner())
|
|
|
|
})
|
2023-02-22 16:21:26 +01:00
|
|
|
}
|