package data_test import ( "testing" "git.akyoto.dev/go/assert" "git.akyoto.dev/go/data" ) var _ data.Storage[string] = (*data.File[string])(nil) func TestFilePersistence(t *testing.T) { users, err := data.NewFile[User]("test") assert.Nil(t, err) defer users.Clear() // Write data to disk users.Set("1", &User{Name: "User 1"}) users.Set("2", &User{Name: "User 2"}) users.Set("3", &User{Name: "User 3"}) users.Sync() // Reload data from disk reload, err := data.NewFile[User]("test") assert.Nil(t, err) user, err := reload.Get("1") assert.Nil(t, err) assert.NotNil(t, user) assert.Equal(t, user.Name, "User 1") user, err = reload.Get("2") assert.Nil(t, err) assert.NotNil(t, user) assert.Equal(t, user.Name, "User 2") user, err = reload.Get("3") assert.Nil(t, err) assert.NotNil(t, user) assert.Equal(t, user.Name, "User 3") }