From ef00ca9698c73679455b22a4bb5f03bbb9d7ead4 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 6 Jul 2023 17:36:22 +0200 Subject: [PATCH] Added a test for persistence --- Collection_test.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Collection_test.go b/Collection_test.go index a1258b4..7e84cbf 100644 --- a/Collection_test.go +++ b/Collection_test.go @@ -11,7 +11,7 @@ type User struct { Name string `json:"name"` } -func TestCollectionGet(t *testing.T) { +func TestGet(t *testing.T) { users, err := ocean.New[User]("test") assert.Nil(t, err) defer users.Clear() @@ -23,6 +23,22 @@ func TestCollectionGet(t *testing.T) { assert.NotNil(t, user) } +func TestCollectionAll(t *testing.T) { + users, err := ocean.New[User]("test") + assert.Nil(t, err) + defer users.Clear() + + users.Set("1", &User{Name: "User 1"}) + users.Set("2", &User{Name: "User 2"}) + count := 0 + + for range users.All() { + count++ + } + + assert.Equal(t, count, 2) +} + func TestInteraction(t *testing.T) { users, err := ocean.New[User]("test") assert.Nil(t, err) @@ -52,18 +68,23 @@ func TestInteraction(t *testing.T) { assert.True(t, !users.Exists("2")) } -func TestCollectionAll(t *testing.T) { +func TestPersistence(t *testing.T) { users, err := ocean.New[User]("test") assert.Nil(t, err) defer users.Clear() users.Set("1", &User{Name: "User 1"}) users.Set("2", &User{Name: "User 2"}) - count := 0 - for range users.All() { - count++ - } + again, err := ocean.New[User]("test") + assert.Nil(t, err) - assert.Equal(t, count, 2) + user1, err := again.Get("1") + assert.Nil(t, err) + + user2, err := again.Get("2") + assert.Nil(t, err) + + assert.NotNil(t, user1) + assert.NotNil(t, user2) }