-
Notifications
You must be signed in to change notification settings - Fork 769
Expand file tree
/
Copy pathtest_fs_binding.py
More file actions
157 lines (109 loc) · 4.87 KB
/
test_fs_binding.py
File metadata and controls
157 lines (109 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
# SPDX-License-Identifier: Apache-2.0
"""AGFS Python Binding Tests for VikingFS interface
Tests the python binding mode of VikingFS which directly uses AGFS implementation
without HTTP server.
"""
import os
import platform
import uuid
from pathlib import Path
import pytest
from openviking.storage.viking_fs import init_viking_fs
from openviking_cli.utils.config.agfs_config import AGFSConfig
# Direct configuration for testing
AGFS_CONF = AGFSConfig(path="/tmp/ov-test", backend="local", mode="binding-client")
# Ensure test directory exists
os.makedirs(AGFS_CONF.path, exist_ok=True)
def get_lib_path() -> str:
"""Get the path to AGFS binding shared library."""
system = platform.system()
if system == "Darwin":
lib_name = "libagfsbinding.dylib"
elif system == "Windows":
lib_name = "libagfsbinding.dll"
else:
lib_name = "libagfsbinding.so"
project_root = Path(__file__).parent.parent.parent
lib_path = project_root / "third_party" / "agfs" / "bin" / lib_name
if lib_path.exists():
return str(lib_path)
env_path = os.environ.get("AGFS_LIB_PATH")
if env_path and Path(env_path).exists():
return env_path
return None
LIB_PATH = get_lib_path()
pytestmark = pytest.mark.skipif(
LIB_PATH is None,
reason="AGFS binding library not found. Build it first: make -C third_party/agfs/agfs-server/cmd/pybinding",
)
@pytest.fixture(scope="module")
async def viking_fs_binding_instance():
"""Initialize VikingFS with binding mode."""
from openviking.utils.agfs_utils import create_agfs_client
# Set lib_path for the test
AGFS_CONF.lib_path = LIB_PATH
# Create AGFS client
agfs_client = create_agfs_client(AGFS_CONF)
# Initialize VikingFS with client
vfs = init_viking_fs(agfs=agfs_client)
# Ensure test directory exists
await vfs.mkdir("viking://temp/", exist_ok=True)
yield vfs
@pytest.mark.asyncio
class TestVikingFSBindingLocal:
"""Test VikingFS operations with binding mode (local backend)."""
async def test_file_operations(self, viking_fs_binding_instance):
"""Test VikingFS file operations: read, write, ls, stat."""
vfs = viking_fs_binding_instance
test_filename = f"binding_file_{uuid.uuid4().hex}.txt"
test_content = "Hello VikingFS Binding! " + uuid.uuid4().hex
test_uri = f"viking://temp/{test_filename}"
await vfs.write(test_uri, test_content)
stat_info = await vfs.stat(test_uri)
assert stat_info["name"] == test_filename
assert not stat_info["isDir"]
entries = await vfs.ls("viking://temp/")
assert any(e["name"] == test_filename for e in entries)
read_data = await vfs.read(test_uri)
assert read_data.decode("utf-8") == test_content
await vfs.rm(test_uri)
async def test_directory_operations(self, viking_fs_binding_instance):
"""Test VikingFS directory operations: mkdir, rm, ls, stat."""
vfs = viking_fs_binding_instance
test_dir = f"binding_dir_{uuid.uuid4().hex}"
test_dir_uri = f"viking://temp/{test_dir}/"
await vfs.mkdir(test_dir_uri)
stat_info = await vfs.stat(test_dir_uri)
assert stat_info["name"] == test_dir
assert stat_info["isDir"]
root_entries = await vfs.ls("viking://temp/")
assert any(e["name"] == test_dir and e["isDir"] for e in root_entries)
file_uri = f"{test_dir_uri}inner.txt"
await vfs.write(file_uri, "inner content")
sub_entries = await vfs.ls(test_dir_uri)
assert any(e["name"] == "inner.txt" for e in sub_entries)
await vfs.rm(test_dir_uri, recursive=True)
root_entries = await vfs.ls("viking://temp/")
assert not any(e["name"] == test_dir for e in root_entries)
async def test_tree_operations(self, viking_fs_binding_instance):
"""Test VikingFS tree operations."""
vfs = viking_fs_binding_instance
base_dir = f"binding_tree_test_{uuid.uuid4().hex}"
sub_dir = f"viking://temp/{base_dir}/a/b/"
file_uri = f"{sub_dir}leaf.txt"
await vfs.mkdir(sub_dir)
await vfs.write(file_uri, "leaf content")
entries = await vfs.tree(f"viking://temp/{base_dir}/")
assert any("leaf.txt" in e["uri"] for e in entries)
await vfs.rm(f"viking://temp/{base_dir}/", recursive=True)
async def test_binary_operations(self, viking_fs_binding_instance):
"""Test VikingFS binary file operations."""
vfs = viking_fs_binding_instance
test_filename = f"binding_binary_{uuid.uuid4().hex}.bin"
test_content = bytes([i % 256 for i in range(256)])
test_uri = f"viking://temp/{test_filename}"
await vfs.write(test_uri, test_content)
read_data = await vfs.read(test_uri)
assert read_data == test_content
await vfs.rm(test_uri)