Added a test for persistence

This commit is contained in:
Eduard Urbach 2023-07-06 17:36:22 +02:00
parent 0add931846
commit ef00ca9698
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -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)
}