diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-25 11:08:58 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-25 11:08:58 -0600 |
| commit | 2b1e14690ea6426a67c0faaaddcfb8aa7360dce7 (patch) | |
| tree | 7f764225e3e3a26bbd7532e72ab99a54e465be92 /app/db/in_memory_repository_test.go | |
| parent | 0053db0d265af313dd281db5cf1e73236cde30c6 (diff) | |
refactor: move db and mountable to app
Diffstat (limited to 'app/db/in_memory_repository_test.go')
| -rw-r--r-- | app/db/in_memory_repository_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/db/in_memory_repository_test.go b/app/db/in_memory_repository_test.go new file mode 100644 index 0000000..bd9d12f --- /dev/null +++ b/app/db/in_memory_repository_test.go @@ -0,0 +1,50 @@ +package db + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" +) + +func TestInMemoryRepository(t *testing.T) { + storage := NewRepository[*domain.Sparkle]() + + t.Run("Save", func(t *testing.T) { + t.Run("an invalid Sparkle", func(t *testing.T) { + err := storage.Save(&domain.Sparkle{Reason: "because"}) + + assert.Error(t, err) + assert.Equal(t, 0, len(storage.All())) + }) + + t.Run("a valid Sparkle", func(t *testing.T) { + sparkle := &domain.Sparkle{Sparklee: "@tanuki", Reason: "because"} + require.NoError(t, storage.Save(sparkle)) + + sparkles := storage.All() + assert.Equal(t, 1, len(sparkles)) + assert.NotEmpty(t, sparkles[0].ID) + assert.Equal(t, "@tanuki", sparkles[0].Sparklee) + assert.Equal(t, "because", sparkles[0].Reason) + }) + }) + + 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") + require.NoError(t, err) + require.NoError(t, storage.Save(sparkle)) + + result := storage.Find(sparkle.ID) + require.NotNil(t, result) + require.Equal(t, sparkle, result) + }) + + t.Run("when the entity does not exist", func(t *testing.T) { + result := storage.Find("unknown") + require.Nil(t, result) + }) + }) +} |
