github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/kvstore/db_test.go (about)

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package kvstore_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
     7  	"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
     8  	"github.com/cockroachdb/pebble"
     9  	"testing"
    10  )
    11  
    12  func TestNewDB(t *testing.T) {
    13  	store, err := kvstore.OpenStore("test")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	defer func() {
    18  		_ = store.Close()
    19  	}()
    20  
    21  	_, err = store.NewDB("TEST_DB")
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	testingStore = store
    27  	testInspectDB(t)
    28  }
    29  
    30  func testInspectDB(t *testing.T) {
    31  	if testingStore == nil {
    32  		return
    33  	}
    34  	it, err := testingStore.RawDB().NewIter(&pebble.IterOptions{})
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	defer func() {
    39  		_ = it.Close()
    40  	}()
    41  
    42  	var isSingleTesting = testutils.IsSingleTesting()
    43  
    44  	for it.First(); it.Valid(); it.Next() {
    45  		valueBytes, valueErr := it.ValueAndErr()
    46  		if valueErr != nil {
    47  			t.Fatal(valueErr)
    48  		}
    49  		t.Log(string(it.Key()), "=>", string(valueBytes))
    50  
    51  		if !isSingleTesting {
    52  			break
    53  		}
    54  	}
    55  }