2024-07-27 15:42:50 +08:00
|
|
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
|
2024-03-24 11:25:35 +08:00
|
|
|
|
|
|
|
|
package kvstore_test
|
|
|
|
|
|
|
|
|
|
import (
|
2024-07-27 15:42:50 +08:00
|
|
|
"testing"
|
|
|
|
|
|
2024-03-24 11:25:35 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
|
2024-04-14 19:59:56 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
2024-03-24 11:25:35 +08:00
|
|
|
"github.com/cockroachdb/pebble"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNewDB(t *testing.T) {
|
|
|
|
|
store, err := kvstore.OpenStore("test")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer func() {
|
|
|
|
|
_ = store.Close()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
_, err = store.NewDB("TEST_DB")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testingStore = store
|
|
|
|
|
testInspectDB(t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testInspectDB(t *testing.T) {
|
|
|
|
|
if testingStore == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
it, err := testingStore.RawDB().NewIter(&pebble.IterOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer func() {
|
|
|
|
|
_ = it.Close()
|
|
|
|
|
}()
|
|
|
|
|
|
2024-04-14 19:59:56 +08:00
|
|
|
var isSingleTesting = testutils.IsSingleTesting()
|
|
|
|
|
|
2024-03-24 11:25:35 +08:00
|
|
|
for it.First(); it.Valid(); it.Next() {
|
|
|
|
|
valueBytes, valueErr := it.ValueAndErr()
|
|
|
|
|
if valueErr != nil {
|
|
|
|
|
t.Fatal(valueErr)
|
|
|
|
|
}
|
|
|
|
|
t.Log(string(it.Key()), "=>", string(valueBytes))
|
2024-04-14 19:59:56 +08:00
|
|
|
|
|
|
|
|
if !isSingleTesting {
|
|
|
|
|
break
|
|
|
|
|
}
|
2024-03-24 11:25:35 +08:00
|
|
|
}
|
|
|
|
|
}
|