WIP: Fixing the tests

This commit is contained in:
Mahmoud Emad
2025-02-16 14:04:17 +00:00
parent ee1ac54dde
commit acd1a4a61d
6 changed files with 51 additions and 52 deletions

View File

@@ -17,17 +17,17 @@ fn encode_metadata(mut e encoder.Encoder, m Metadata) {
}
// decode_metadata decodes the common metadata structure
fn decode_metadata(mut d encoder.Decoder) Metadata {
id := d.get_u32()
name := d.get_string()
file_type_byte := d.get_u8()
size := d.get_u64()
created_at := d.get_i64()
modified_at := d.get_i64()
accessed_at := d.get_i64()
mode := d.get_u32()
owner := d.get_string()
group := d.get_string()
fn decode_metadata(mut d encoder.Decoder) !Metadata {
id := d.get_u32()!
name := d.get_string()!
file_type_byte := d.get_u8()!
size := d.get_u64()!
created_at := d.get_i64()!
modified_at := d.get_i64()!
accessed_at := d.get_i64()!
mode := d.get_u32()!
owner := d.get_string()!
group := d.get_string()!
return Metadata{
id: id
@@ -69,28 +69,28 @@ pub fn (dir Directory) encode() []u8 {
// decode_directory decodes a binary format back to Directory
pub fn decode_directory(data []u8) !Directory {
mut d := encoder.decoder_new(data)
version := d.get_u8()
version := d.get_u8()!
if version != 1 {
return error('Unsupported version ${version}')
}
type_byte := d.get_u8()
type_byte := d.get_u8()!
if type_byte != u8(FileType.directory) {
return error('Invalid type byte for directory')
}
// Decode metadata
metadata := decode_metadata(mut d)
metadata := decode_metadata(mut d)!
// Decode parent_id
parent_id := d.get_u32()
parent_id := d.get_u32()!
// Decode children IDs
children_count := int(d.get_u16())
children_count := int(d.get_u16()!)
mut children := []u32{cap: children_count}
for _ in 0 .. children_count {
children << d.get_u32()
children << d.get_u32()!
}
return Directory{
@@ -124,24 +124,24 @@ pub fn (f File) encode() []u8 {
// decode_file decodes a binary format back to File
pub fn decode_file(data []u8) !File {
mut d := encoder.decoder_new(data)
version := d.get_u8()
version := d.get_u8()!
if version != 1 {
return error('Unsupported version ${version}')
}
type_byte := d.get_u8()
type_byte := d.get_u8()!
if type_byte != u8(FileType.file) {
return error('Invalid type byte for file')
}
// Decode metadata
metadata := decode_metadata(mut d)
metadata := decode_metadata(mut d)!
// Decode parent_id
parent_id := d.get_u32()
parent_id := d.get_u32()!
// Decode file data
data_content := d.get_string()
data_content := d.get_string()!
return File{
metadata: metadata
@@ -174,24 +174,24 @@ pub fn (sl Symlink) encode() []u8 {
// decode_symlink decodes a binary format back to Symlink
pub fn decode_symlink(data []u8) !Symlink {
mut d := encoder.decoder_new(data)
version := d.get_u8()
version := d.get_u8()!
if version != 1 {
return error('Unsupported version ${version}')
}
type_byte := d.get_u8()
type_byte := d.get_u8()!
if type_byte != u8(FileType.symlink) {
return error('Invalid type byte for symlink')
}
// Decode metadata
metadata := decode_metadata(mut d)
metadata := decode_metadata(mut d)!
// Decode parent_id
parent_id := d.get_u32()
parent_id := d.get_u32()!
// Decode target path
target := d.get_string()
target := d.get_string()!
return Symlink{
metadata: metadata

View File

@@ -72,19 +72,19 @@ pub fn (mut fs OurDBFS) save_entry(entry FSEntry) !u32 {
match entry {
Directory {
encoded := entry.encode()
return fs.db_meta.set(entry.metadata.id, encoded) or {
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
return error('Failed to save directory on id:${entry.metadata.id}: ${err}')
}
}
File {
encoded := entry.encode()
return fs.db_meta.set(entry.metadata.id, encoded) or {
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
return error('Failed to save file on id:${entry.metadata.id}: ${err}')
}
}
Symlink {
encoded := entry.encode()
return fs.db_meta.set(entry.metadata.id, encoded) or {
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
return error('Failed to save symlink on id:${entry.metadata.id}: ${err}')
}
}

View File

@@ -59,7 +59,7 @@ fn test_vfs_implementations() ! {
// Cleanup
local_vfs.delete('test2.txt')!
local_vfs.delete('subdir')!
local_vfs.delete('test_link.txt')!
local_vfs.delete('test_link.txt') or {}
os.rmdir('/tmp/test_local_vfs') or {}
}

View File

@@ -1,5 +1,6 @@
module vfsnested
import freeflowuniverse.herolib.vfs.vfscore
import os
fn test_nested() ! {

View File

@@ -8,7 +8,7 @@ import time
// OurDBVFS represents a VFS that uses OurDB as the underlying storage
pub struct OurDBVFS {
mut:
core &ourdb_fs.VFS
core &ourdb_fs.OurDBFS
}
// new creates a new OurDBVFS instance
@@ -155,20 +155,19 @@ pub fn (mut self OurDBVFS) destroy() ! {
}
// Helper functions
fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry {
if path == '/' {
return self.core.get_root()!
return *self.core.get_root()! // Dereference to return a value
}
mut current := self.core.get_root()!
mut current := self.core.get_root()! // This is already a reference (&Directory)
parts := path.trim_left('/').split('/')
for i := 0; i < parts.len; i++ {
found := false
children := current.children(false)!
mut found := false
mut children := current.children(false)!
for child in children {
for mut child in children {
if child.metadata.name == parts[i] {
match child {
ourdb_fs.Directory {
@@ -178,7 +177,7 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry {
}
else {
if i == parts.len - 1 {
return child
return child // `child` is already a value, so return it directly
} else {
return error('Not a directory: ${parts[i]}')
}
@@ -192,7 +191,7 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry {
}
}
return current
return *current // Dereference to return a value
}
fn (mut self OurDBVFS) get_directory(path string) !&ourdb_fs.Directory {

View File

@@ -30,12 +30,11 @@ fn load_test_cache() TestCache {
} }
}
fn in_github_actions() bool{
a:=os.environ()["GITHUB_ACTIONS"] or {return false}
fn in_github_actions() bool {
a := os.environ()['GITHUB_ACTIONS'] or { return false }
return true
}
// Save the test cache to JSON file
fn save_test_cache(cache TestCache) {
json_str := json.encode_pretty(cache)
@@ -168,6 +167,7 @@ lib/code
lib/clients
lib/core
lib/develop
lib/vfs
// lib/crypt
'
@@ -183,11 +183,9 @@ data/radixtree
clients/livekit
'
if in_github_actions(){
println("**** WE ARE IN GITHUB ACTION")
tests_ignore+="\nosal/tmux\n"
if in_github_actions() {
println('**** WE ARE IN GITHUB ACTION')
tests_ignore += '\nosal/tmux\n'
}
tests_error := '
@@ -218,7 +216,7 @@ test_files_error := tests_error.split('\n').filter(it.trim_space() != '')
mut cache := load_test_cache()
println('Test cache loaded from ${cache_file}')
println("tests to ignore")
println('tests to ignore')
println(tests_ignore)
// Run each test with proper v command flags
@@ -239,12 +237,13 @@ for test in test_files {
// If directory, run tests for each .v file in it recursively
files := os.walk_ext(full_path, '.v')
for file in files {
process_test_file(file, norm_dir_of_script, test_files_ignore, test_files_error, mut cache)!
process_test_file(file, norm_dir_of_script, test_files_ignore, test_files_error, mut
cache)!
}
} else if os.is_file(full_path) {
process_test_file(full_path, norm_dir_of_script, test_files_ignore, test_files_error, mut cache)!
process_test_file(full_path, norm_dir_of_script, test_files_ignore, test_files_error, mut
cache)!
}
}
println('All (non skipped) tests ok')