2023-05-31 12:49:45 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-03-14 12:33:52 +00:00
|
|
|
kv "git.sr.ht/~ashkeel/kilovolt/v12"
|
2023-05-31 12:49:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func CreateInMemoryLocalClient(t *testing.T) (*LocalDBClient, kv.Driver) {
|
|
|
|
// Create in-memory store and hub
|
|
|
|
inMemoryStore := kv.MakeBackend()
|
2024-03-14 12:33:52 +00:00
|
|
|
hub, err := kv.NewHub(inMemoryStore, kv.HubOptions{})
|
2023-05-31 12:49:45 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
go hub.Run()
|
|
|
|
|
|
|
|
// Create local client
|
2024-03-14 12:33:52 +00:00
|
|
|
client, err := NewLocalClient(hub)
|
2023-05-31 12:49:45 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, inMemoryStore
|
|
|
|
}
|
|
|
|
|
|
|
|
func CleanupLocalClient(client *LocalDBClient) {
|
|
|
|
if client.hub != nil {
|
|
|
|
_ = client.Close()
|
|
|
|
client.hub.Close()
|
|
|
|
}
|
|
|
|
}
|