Added a test for persistence
This commit is contained in:
parent
0add931846
commit
ef00ca9698
@ -11,7 +11,7 @@ type User struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCollectionGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
users, err := ocean.New[User]("test")
|
users, err := ocean.New[User]("test")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer users.Clear()
|
defer users.Clear()
|
||||||
@ -23,6 +23,22 @@ func TestCollectionGet(t *testing.T) {
|
|||||||
assert.NotNil(t, user)
|
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) {
|
func TestInteraction(t *testing.T) {
|
||||||
users, err := ocean.New[User]("test")
|
users, err := ocean.New[User]("test")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@ -52,18 +68,23 @@ func TestInteraction(t *testing.T) {
|
|||||||
assert.True(t, !users.Exists("2"))
|
assert.True(t, !users.Exists("2"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCollectionAll(t *testing.T) {
|
func TestPersistence(t *testing.T) {
|
||||||
users, err := ocean.New[User]("test")
|
users, err := ocean.New[User]("test")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer users.Clear()
|
defer users.Clear()
|
||||||
|
|
||||||
users.Set("1", &User{Name: "User 1"})
|
users.Set("1", &User{Name: "User 1"})
|
||||||
users.Set("2", &User{Name: "User 2"})
|
users.Set("2", &User{Name: "User 2"})
|
||||||
count := 0
|
|
||||||
|
|
||||||
for range users.All() {
|
again, err := ocean.New[User]("test")
|
||||||
count++
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user