This commit is contained in:
桜華 2023-06-24 02:31:03 +08:00
parent c77e3b9db7
commit 11679b5c98
3 changed files with 50 additions and 0 deletions

2
.gitignore vendored
View File

@ -8,6 +8,8 @@
*.so *.so
*.dylib *.dylib
data/
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View File

@ -184,3 +184,8 @@ func New(path string) *ToEntangle {
db: db, db: db,
} }
} }
// Close 关闭 leveldb
func (t *ToEntangle) Close() {
t.db.Close()
}

43
to_entangle_test.go Normal file
View File

@ -0,0 +1,43 @@
package toentangle
import (
"fmt"
"os"
"testing"
)
func TestToEntangle_Get(t *testing.T) {
// 创建一个 ToEntangle
entangle := New("data")
// 添加一对数据, 使其双向绑定
entangle.Add("a", "b")
entangle.Add("a", "c")
// 获取 a 的全部绑定数据
arr, _ := entangle.Get("a")
fmt.Println(arr)
if len(arr) != 2 || arr[0] != "b" || arr[1] != "c" {
t.Errorf("Get(\"a\") = %v; want [\"b\", \"c\"]", arr)
}
// 获取 b 的全部绑定数据
arr, _ = entangle.Get("b")
fmt.Println(arr)
if len(arr) != 1 || arr[0] != "a" {
t.Errorf("Get(\"b\") = %v; want [\"a\"]", arr)
}
// 获取 c 的全部绑定数据
arr, _ = entangle.Get("c")
fmt.Println(arr)
if len(arr) != 1 || arr[0] != "a" {
t.Errorf("Get(\"c\") = %v; want [\"a\"]", arr)
}
// 清理 leveldb
entangle.Close()
// 删除 data 文件夹
os.RemoveAll("data")
}