Skip to main content

Module tests

Module tests 

Source
Expand description

Generic test suite for file system operations.

This module provides comprehensive tests for any implementation of the FileSystemOperations trait. It includes tests for:

  • File operations (create, lookup, remove)
  • Directory operations (create, lookup, remove, nested)
  • Rename and move operations
  • Attribute get/set operations
  • Error handling and edge cases
  • File system consistency
  • Special cases (root directory, long names, special characters)

§Usage

The easiest way to test your file system implementation is to use the implement_file_system_tests! macro, which generates individual test functions for each test category:

ⓘ
use file_system::implement_file_system_tests;

mod tests {
    use super::*;
     
    implement_file_system_tests! {
        instance: MyFileSystem::new()
    }
}

This will generate 32+ individual #[test] functions, each testing a specific aspect of your file system implementation.

§Using Individual Test Functions

You can also call individual test functions directly:

ⓘ
use file_system::operations::file_system::tests;

#[test]
fn test_my_file_system() {
    let fs = MyFileSystem::new();
     
    // Run all tests
    tests::run_all_tests(&fs);
     
    // Or run individual test categories
    tests::test_file_operations(&fs);
    tests::test_directory_operations(&fs);
    tests::test_rename_operations(&fs);
}

§Test Categories

§File System Structure Tests

  • test_file_operations - Basic file CRUD operations
  • test_directory_operations - Basic directory operations
  • test_nested_directories - Nested directory hierarchy
  • test_rename_operations - File/directory rename and move
  • test_attribute_operations - Metadata get/set operations

§File I/O Tests

  • test_file_read_operations - Reading data from files
  • test_file_write_operations - Writing data to files
  • test_file_write_pattern - Pattern-based writing
  • test_file_write_vectored - Vectored (scatter-gather) I/O
  • test_file_position_operations - Position-based read/write
  • test_file_read_until - Reading until delimiter
  • test_file_flush - Flushing buffered data
  • test_large_file_operations - Large file handling

§Directory I/O Tests

  • test_directory_read_operations - Reading directory entries
  • test_directory_position_operations - Directory position management
  • test_directory_rewind - Rewinding directory stream
  • test_empty_directory_read - Reading empty directories

§Error Handling & Edge Cases

  • test_error_handling - Error case validation
  • test_file_system_consistency - Consistency checks
  • test_root_directory_operations - Root directory special cases
  • test_invalid_paths - Invalid path handling

§Test Execution

  • implement_file_system_tests! - Macro to generate all test functions (recommended)
  • run_all_tests - Function to execute all test categories sequentially

Macros§

implement_file_system_tests
Macro to implement all file system operation tests for a given file system instance.

Structs§

FileSystemTestCapabilities
Attribute capabilities used by the generic test suite.

Functions§

test_attribute_operations
Test attribute get/set operations
test_attribute_operations_with_capabilities
Test attribute operations for a backend with explicitly configured readable and writable fields.
test_directory_attributes
Test attribute operations on directories
test_directory_entry_metadata
Test directory entry metadata
test_directory_operations
Test directory operations: create, lookup, remove
test_directory_position_operations
Test directory position operations
test_directory_read_operations
Test directory read operations
test_directory_rewind
Test directory rewind and re-read
test_empty_directory_read
Test reading empty directory
test_empty_file_operations
Test empty file operations
test_error_handling
Test error handling for various scenarios
test_file_creation_edge_cases
Test file creation with various edge cases
test_file_flush
Test file flush operation
test_file_operations
Test basic file operations: create, lookup, remove
test_file_position_operations
Test file read/write at specific positions
test_file_read_operations
Test file read operations (when FileOperations::read is available)
test_file_read_until
Test file read until delimiter
test_file_system_consistency
Test file system consistency
test_file_system_operations
Generic test suite for file system operations.
test_file_write_operations
Test file write operations with various patterns
test_file_write_pattern
Test file write pattern operations
test_file_write_vectored
Test file write vectored operations
test_invalid_paths
Test invalid path handling
test_large_file_operations
Test large file operations
test_long_filenames
Test long file names
test_lookup_with_flags
Test file lookup with different flags
test_move_between_directories
Test moving files between directories
test_multiple_operations
Test concurrent operations (if file system supports it)
test_nested_directories
Test nested directory operations
test_open_close_operations
Test open and close operations
test_rename_edge_cases
Test rename edge cases
test_rename_operations
Test rename/move operations
test_root_directory_operations
Test operations on root directory
test_special_characters_in_names
Test special characters in filenames