mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	改进单元测试,以便于可以使用go test ../...进行执行
This commit is contained in:
		@@ -11,4 +11,4 @@ go run -tags=${TAG}  ../cmd/edge-node/main.go stop
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# reference: https://pkg.go.dev/cmd/go/internal/test
 | 
					# reference: https://pkg.go.dev/cmd/go/internal/test
 | 
				
			||||||
go clean -testcache
 | 
					go clean -testcache
 | 
				
			||||||
go test -timeout 10s -tags="${TAG}" -cover ../...
 | 
					go test -timeout 60s -tags="${TAG}" -cover ../...
 | 
				
			||||||
@@ -18,14 +18,6 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var testingKVList *caches.KVFileList
 | 
					var testingKVList *caches.KVFileList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestMain(m *testing.M) {
 | 
					 | 
				
			||||||
	m.Run()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if testingKVList != nil {
 | 
					 | 
				
			||||||
		_ = testingKVList.Close()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func testOpenKVFileList(t *testing.T) *caches.KVFileList {
 | 
					func testOpenKVFileList(t *testing.T) *caches.KVFileList {
 | 
				
			||||||
	var list = caches.NewKVFileList(Tea.Root + "/data/stores/cache-stores")
 | 
						var list = caches.NewKVFileList(Tea.Root + "/data/stores/cache-stores")
 | 
				
			||||||
	err := list.Init()
 | 
						err := list.Init()
 | 
				
			||||||
@@ -38,11 +30,18 @@ func testOpenKVFileList(t *testing.T) *caches.KVFileList {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestNewKVFileList(t *testing.T) {
 | 
					func TestNewKVFileList(t *testing.T) {
 | 
				
			||||||
	_ = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						err := list.Close()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Add(t *testing.T) {
 | 
					func TestKVFileList_Add(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := list.Add(stringutil.Md5("123456"), &caches.Item{
 | 
						err := list.Add(stringutil.Md5("123456"), &caches.Item{
 | 
				
			||||||
		Type:       caches.ItemTypeFile,
 | 
							Type:       caches.ItemTypeFile,
 | 
				
			||||||
@@ -67,6 +66,9 @@ func TestKVFileList_Add_Many(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const start = 0
 | 
						const start = 0
 | 
				
			||||||
	const count = 1_000_000
 | 
						const count = 1_000_000
 | 
				
			||||||
@@ -113,6 +115,9 @@ func TestKVFileList_Add_Many_Suffix(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const start = 0
 | 
						const start = 0
 | 
				
			||||||
	const count = 1000
 | 
						const count = 1000
 | 
				
			||||||
@@ -155,6 +160,10 @@ func TestKVFileList_Add_Many_Suffix(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Exist(t *testing.T) {
 | 
					func TestKVFileList_Exist(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, hash := range []string{
 | 
						for _, hash := range []string{
 | 
				
			||||||
		stringutil.Md5("123456"),
 | 
							stringutil.Md5("123456"),
 | 
				
			||||||
		stringutil.Md5("654321"),
 | 
							stringutil.Md5("654321"),
 | 
				
			||||||
@@ -169,6 +178,10 @@ func TestKVFileList_Exist(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_ExistQuick(t *testing.T) {
 | 
					func TestKVFileList_ExistQuick(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, hash := range []string{
 | 
						for _, hash := range []string{
 | 
				
			||||||
		stringutil.Md5("123456"),
 | 
							stringutil.Md5("123456"),
 | 
				
			||||||
		stringutil.Md5("654321"),
 | 
							stringutil.Md5("654321"),
 | 
				
			||||||
@@ -183,6 +196,10 @@ func TestKVFileList_ExistQuick(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Remove(t *testing.T) {
 | 
					func TestKVFileList_Remove(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, hash := range []string{
 | 
						for _, hash := range []string{
 | 
				
			||||||
		stringutil.Md5("123456"),
 | 
							stringutil.Md5("123456"),
 | 
				
			||||||
		stringutil.Md5("654321"),
 | 
							stringutil.Md5("654321"),
 | 
				
			||||||
@@ -196,6 +213,10 @@ func TestKVFileList_Remove(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_CleanAll(t *testing.T) {
 | 
					func TestKVFileList_CleanAll(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := list.CleanAll()
 | 
						err := list.CleanAll()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -208,6 +229,10 @@ func TestKVFileList_Inspect(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := list.TestInspect(t)
 | 
						err := list.TestInspect(t)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -216,6 +241,10 @@ func TestKVFileList_Inspect(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Purge(t *testing.T) {
 | 
					func TestKVFileList_Purge(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	count, err := list.Purge(4_000, func(hash string) error {
 | 
						count, err := list.Purge(4_000, func(hash string) error {
 | 
				
			||||||
		//t.Log("hash:", hash)
 | 
							//t.Log("hash:", hash)
 | 
				
			||||||
@@ -229,6 +258,10 @@ func TestKVFileList_Purge(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_PurgeLFU(t *testing.T) {
 | 
					func TestKVFileList_PurgeLFU(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	err := list.PurgeLFU(20000, func(hash string) error {
 | 
						err := list.PurgeLFU(20000, func(hash string) error {
 | 
				
			||||||
		t.Log("hash:", hash)
 | 
							t.Log("hash:", hash)
 | 
				
			||||||
@@ -242,6 +275,10 @@ func TestKVFileList_PurgeLFU(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Count(t *testing.T) {
 | 
					func TestKVFileList_Count(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	count, err := list.Count()
 | 
						count, err := list.Count()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -252,6 +289,10 @@ func TestKVFileList_Count(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_Stat(t *testing.T) {
 | 
					func TestKVFileList_Stat(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	stat, err := list.Stat(func(hash string) bool {
 | 
						stat, err := list.Stat(func(hash string) bool {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
@@ -264,6 +305,10 @@ func TestKVFileList_Stat(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_CleanPrefix(t *testing.T) {
 | 
					func TestKVFileList_CleanPrefix(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
@@ -279,6 +324,10 @@ func TestKVFileList_CleanPrefix(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_CleanMatchPrefix(t *testing.T) {
 | 
					func TestKVFileList_CleanMatchPrefix(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
@@ -294,6 +343,10 @@ func TestKVFileList_CleanMatchPrefix(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestKVFileList_CleanMatchKey(t *testing.T) {
 | 
					func TestKVFileList_CleanMatchKey(t *testing.T) {
 | 
				
			||||||
	var list = testOpenKVFileList(t)
 | 
						var list = testOpenKVFileList(t)
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = list.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ package kvstore_test
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
 | 
				
			||||||
 | 
						"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
 | 
				
			||||||
	"github.com/cockroachdb/pebble"
 | 
						"github.com/cockroachdb/pebble"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -38,11 +39,17 @@ func testInspectDB(t *testing.T) {
 | 
				
			|||||||
		_ = it.Close()
 | 
							_ = it.Close()
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var isSingleTesting = testutils.IsSingleTesting()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for it.First(); it.Valid(); it.Next() {
 | 
						for it.First(); it.Valid(); it.Next() {
 | 
				
			||||||
		valueBytes, valueErr := it.ValueAndErr()
 | 
							valueBytes, valueErr := it.ValueAndErr()
 | 
				
			||||||
		if valueErr != nil {
 | 
							if valueErr != nil {
 | 
				
			||||||
			t.Fatal(valueErr)
 | 
								t.Fatal(valueErr)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		t.Log(string(it.Key()), "=>", string(valueBytes))
 | 
							t.Log(string(it.Key()), "=>", string(valueBytes))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !isSingleTesting {
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ package kvstore_test
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
 | 
				
			||||||
	"github.com/iwind/TeaGo/assert"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
@@ -14,6 +14,10 @@ import (
 | 
				
			|||||||
func TestQuery_FindAll(t *testing.T) {
 | 
					func TestQuery_FindAll(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
 | 
							t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
 | 
				
			||||||
@@ -37,6 +41,10 @@ func TestQuery_FindAll(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Break(t *testing.T) {
 | 
					func TestQuery_FindAll_Break(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
 | 
							t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
 | 
				
			||||||
@@ -57,14 +65,16 @@ func TestQuery_FindAll_Break(t *testing.T) {
 | 
				
			|||||||
			return count < 3, nil
 | 
								return count < 3, nil
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Log(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestQuery_FindAll_Break_Closed(t *testing.T) {
 | 
					func TestQuery_FindAll_Break_Closed(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var a = assert.NewAssertion(t)
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
@@ -86,12 +96,15 @@ func TestQuery_FindAll_Break_Closed(t *testing.T) {
 | 
				
			|||||||
			return count < 3, nil
 | 
								return count < 3, nil
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	t.Log("expected error:", err)
 | 
						t.Log("expected error:", err)
 | 
				
			||||||
	a.IsTrue(err != nil)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestQuery_FindAll_Desc(t *testing.T) {
 | 
					func TestQuery_FindAll_Desc(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := table.Query().
 | 
						err := table.Query().
 | 
				
			||||||
		Desc().
 | 
							Desc().
 | 
				
			||||||
		Limit(10).
 | 
							Limit(10).
 | 
				
			||||||
@@ -107,6 +120,10 @@ func TestQuery_FindAll_Desc(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Offset(t *testing.T) {
 | 
					func TestQuery_FindAll_Offset(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		t.Log("=== forward ===")
 | 
							t.Log("=== forward ===")
 | 
				
			||||||
		err := table.Query().
 | 
							err := table.Query().
 | 
				
			||||||
@@ -141,6 +158,10 @@ func TestQuery_FindAll_Offset(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Skip(t *testing.T) {
 | 
					func TestQuery_FindAll_Skip(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		err := table.Query().
 | 
							err := table.Query().
 | 
				
			||||||
			Offset("a3").
 | 
								Offset("a3").
 | 
				
			||||||
@@ -161,6 +182,10 @@ func TestQuery_FindAll_Skip(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Count(t *testing.T) {
 | 
					func TestQuery_FindAll_Count(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var count int
 | 
						var count int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
@@ -186,6 +211,10 @@ func TestQuery_FindAll_Count(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Field(t *testing.T) {
 | 
					func TestQuery_FindAll_Field(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		var costSeconds = time.Since(before).Seconds()
 | 
							var costSeconds = time.Since(before).Seconds()
 | 
				
			||||||
@@ -236,17 +265,26 @@ func TestQuery_FindAll_Field(t *testing.T) {
 | 
				
			|||||||
func TestQuery_FindAll_Field_Many(t *testing.T) {
 | 
					func TestQuery_FindAll_Field_Many(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		var costSeconds = time.Since(before).Seconds()
 | 
							var costSeconds = time.Since(before).Seconds()
 | 
				
			||||||
		t.Log("cost:", costSeconds*1000, "ms", "qps:", int(1/costSeconds))
 | 
							t.Log("cost:", costSeconds*1000, "ms", "qps:", int(1/costSeconds))
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var count = 3
 | 
				
			||||||
 | 
						if testutils.IsSingleTesting() {
 | 
				
			||||||
 | 
							count = 1_000
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := table.
 | 
						err := table.
 | 
				
			||||||
		Query().
 | 
							Query().
 | 
				
			||||||
		FieldAsc("expiresAt").
 | 
							FieldAsc("expiresAt").
 | 
				
			||||||
		KeysOnly().
 | 
							KeysOnly().
 | 
				
			||||||
		Limit(1000).
 | 
							Limit(count).
 | 
				
			||||||
		FindAll(func(tx *kvstore.Tx[*testCachedItem], item kvstore.Item[*testCachedItem]) (goNext bool, err error) {
 | 
							FindAll(func(tx *kvstore.Tx[*testCachedItem], item kvstore.Item[*testCachedItem]) (goNext bool, err error) {
 | 
				
			||||||
			t.Log(item.Key, "=>", item.Value)
 | 
								t.Log(item.Key, "=>", item.Value)
 | 
				
			||||||
			return true, nil
 | 
								return true, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -142,6 +142,8 @@ func TestStore_CloseTwice(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestStore_Count(t *testing.T) {
 | 
					func TestStore_Count(t *testing.T) {
 | 
				
			||||||
	testCountStore(t)
 | 
						testCountStore(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ = testingStore.Close()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var testingStore *kvstore.Store
 | 
					var testingStore *kvstore.Store
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,6 +50,10 @@ func (this *testCacheItemEncoder[T]) EncodeField(value T, fieldName string) ([]b
 | 
				
			|||||||
func TestTable_AddField(t *testing.T) {
 | 
					func TestTable_AddField(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := table.AddFields("expiresAt")
 | 
						err := table.AddFields("expiresAt")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -103,6 +107,10 @@ func TestTable_AddField_Many(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		err := table.AddFields("expiresAt")
 | 
							err := table.AddFields("expiresAt")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@@ -157,6 +165,10 @@ func TestTable_AddField_Delete_Many(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		err := table.AddFields("expiresAt")
 | 
							err := table.AddFields("expiresAt")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@@ -205,6 +217,10 @@ func TestTable_AddField_Delete_Many(t *testing.T) {
 | 
				
			|||||||
func TestTable_DropField(t *testing.T) {
 | 
					func TestTable_DropField(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		var costSeconds = time.Since(before).Seconds()
 | 
							var costSeconds = time.Since(before).Seconds()
 | 
				
			||||||
@@ -242,6 +258,10 @@ func TestTable_DropField(t *testing.T) {
 | 
				
			|||||||
func TestTable_Inspect(t *testing.T) {
 | 
					func TestTable_Inspect(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := table.AddFields("expiresAt")
 | 
						err := table.AddFields("expiresAt")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -249,6 +249,10 @@ func TestTable_Delete_Empty(t *testing.T) {
 | 
				
			|||||||
func TestTable_Count(t *testing.T) {
 | 
					func TestTable_Count(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	count, err := table.Count()
 | 
						count, err := table.Count()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -265,6 +269,11 @@ func TestTable_Count(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestTable_Truncate(t *testing.T) {
 | 
					func TestTable_Truncate(t *testing.T) {
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var before = time.Now()
 | 
						var before = time.Now()
 | 
				
			||||||
	err := table.Truncate()
 | 
						err := table.Truncate()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -282,6 +291,11 @@ func TestTable_ComposeFieldKey(t *testing.T) {
 | 
				
			|||||||
	var a = assert.NewAssertion(t)
 | 
						var a = assert.NewAssertion(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
						var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							_ = testingStore.Close()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var fieldKeyBytes = table.ComposeFieldKey([]byte("Lily"), "username", []byte("lucy"))
 | 
						var fieldKeyBytes = table.ComposeFieldKey([]byte("Lily"), "username", []byte("lucy"))
 | 
				
			||||||
	t.Log(string(fieldKeyBytes))
 | 
						t.Log(string(fieldKeyBytes))
 | 
				
			||||||
	fieldValueBytes, keyValueBytes, err := table.DecodeFieldKey("username", fieldKeyBytes)
 | 
						fieldValueBytes, keyValueBytes, err := table.DecodeFieldKey("username", fieldKeyBytes)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestRemoveDB(t *testing.T) {
 | 
					func TestRemoveDB(t *testing.T) {
 | 
				
			||||||
	err := kvstore.RemoveStore(Tea.Root + "/data/stores/test.store")
 | 
						err := kvstore.RemoveStore(Tea.Root + "/data/stores/test2.store")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user