test: Add more comprehensive tests for vfsourdb

- Added tests to verify directory listing functionality after
  creating and moving directories.
- Improved test coverage for file operations within directories.
- Ensured tests accurately reflect the updated behavior of
  `dir_list` function.
This commit is contained in:
Mahmoud Emad
2025-02-25 13:13:41 +02:00
parent 1f58676278
commit 4ed80481aa
2 changed files with 18 additions and 2 deletions

View File

@@ -42,8 +42,12 @@ fn test_directory_operations() ! {
assert test_dir.get_metadata().file_type == .directory assert test_dir.get_metadata().file_type == .directory
// Test listing // Test listing
entries := vfs.dir_list('/')! mut entries := vfs.dir_list('/')!
assert entries.any(it.get_metadata().name == 'test_dir') assert entries.any(it.get_metadata().name == 'test_dir')
// Test listing entries in the created directory
entries = vfs.dir_list('/test_dir')!
assert entries.len == 0
} }
fn test_file_operations() ! { fn test_file_operations() ! {
@@ -63,6 +67,10 @@ fn test_file_operations() ! {
test_content := 'Hello, World!'.bytes() test_content := 'Hello, World!'.bytes()
vfs.file_write('/test_dir/test.txt', test_content)! vfs.file_write('/test_dir/test.txt', test_content)!
assert vfs.file_read('/test_dir/test.txt')! == test_content assert vfs.file_read('/test_dir/test.txt')! == test_content
// Test listing entries in the created directory
entries := vfs.dir_list('/test_dir')!
assert entries.len == 1
} }
fn test_directory_move() ! { fn test_directory_move() ! {
@@ -74,11 +82,19 @@ fn test_directory_move() ! {
vfs.dir_create('/test_dir')! vfs.dir_create('/test_dir')!
vfs.file_create('/test_dir/test.txt')! vfs.file_create('/test_dir/test.txt')!
// Test listing entries in the created directory
mut entries := vfs.dir_list('/test_dir')!
assert entries.len == 1
// Perform move // Perform move
moved_dir := vfs.move('/test_dir', '/test_dir2')! moved_dir := vfs.move('/test_dir', '/test_dir2')!
assert moved_dir.get_metadata().name == 'test_dir2' assert moved_dir.get_metadata().name == 'test_dir2'
assert vfs.exists('/test_dir') == false assert vfs.exists('/test_dir') == false
assert vfs.exists('/test_dir2/test.txt') == true assert vfs.exists('/test_dir2/test.txt') == true
// Test listing entries in the created directory
entries = vfs.dir_list('/test_dir2')!
assert entries.len == 1
} }
fn test_directory_copy() ! { fn test_directory_copy() ! {

View File

@@ -167,7 +167,7 @@ lib/code
lib/clients lib/clients
lib/core lib/core
lib/develop lib/develop
// lib/vfs lib/vfs
// lib/crypt // lib/crypt
' '