summaryrefslogtreecommitdiff
path: root/app/db
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-13 14:39:17 -0600
committermo khan <mo@mokhan.ca>2025-06-13 14:39:17 -0600
commit210e71b7023ed02531c46f1a3846bc6d025ba61f (patch)
tree837bc885816d9deeeff784ab6f2bc59621c1752c /app/db
parentfb1771de02c3ffffcb69c577696d0190863a9a6f (diff)
test: add test to produce error that bypasses repository interface
Diffstat (limited to 'app/db')
-rw-r--r--app/db/in_memory_repository_test.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/app/db/in_memory_repository_test.go b/app/db/in_memory_repository_test.go
index 37fcbe0..9c44fa7 100644
--- a/app/db/in_memory_repository_test.go
+++ b/app/db/in_memory_repository_test.go
@@ -15,9 +15,7 @@ func TestInMemoryRepository(t *testing.T) {
t.Run("Save", func(t *testing.T) {
t.Run("an invalid Sparkle", func(t *testing.T) {
- err := storage.Save(t.Context(), &domain.Sparkle{Reason: "because"})
-
- assert.Error(t, err)
+ assert.Error(t, storage.Save(t.Context(), &domain.Sparkle{Reason: "because"}))
assert.Equal(t, 0, len(storage.All(t.Context())))
})
@@ -93,6 +91,28 @@ func TestInMemoryRepository(t *testing.T) {
})
})
+ t.Run("All", func(t *testing.T) {
+ repository := NewRepository[*domain.Sparkle]()
+ require.NoError(t, repository.Save(t.Context(), &domain.Sparkle{
+ Sparklee: "@tanuki",
+ Reason: "because",
+ }))
+
+ t.Run("prevents unintended modifications", func(t *testing.T) {
+ items := repository.All(t.Context())
+ require.Equal(t, 1, len(items))
+
+ sparkle := items[0]
+ sparkle.Reason = "haha"
+
+ assert.Equal(t, "because", repository.All(t.Context())[0].Reason)
+ })
+
+ t.Run("prevents race conditions", func(t *testing.T) {
+ t.Skip()
+ })
+ })
+
t.Run("Find", func(t *testing.T) {
t.Run("when the entity exists", func(t *testing.T) {
sparkle, err := domain.NewSparkle("@tanuki for testing this func")