test: add firmware service unit tests#85
Merged
JanZachmann merged 9 commits intoomnect:mainfrom Jan 14, 2026
Merged
Conversation
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
- Implemented auth.spec.ts, device.spec.ts, network.spec.ts - Added centrifugo fixture helper - Fixed Centrifugo subscription in App.vue - Improved test scripts for argument forwarding - Configured playwright to ignore HTTPS errors - Added jsonwebtoken for test token generation Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Add comprehensive unit tests for NetworkConfigService covering: - Request validation (DHCP, static IP, netmask boundaries) - INI file generation for systemd-networkd - Rollback response structure - camelCase serialization/deserialization - enable_rollback field handling Tests use tempfile for filesystem operations and replicate production INI generation logic in isolation. Note: Rollback file I/O tests not included due to hardcoded paths (/network/, /tmp/). Would require path injection refactor. 14 tests added, bringing total backend tests from 40 to 54. Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Expand firmware service test coverage to validate file operations and device service delegation: - clear_data_folder removes files, preserves subdirectories - load_update forwards requests to device service client - run_update forwards requests with validation flag Tests use mockall to mock DeviceServiceClient for async operations. Note: clear_data_folder tests share temp directory and may race in parallel. Run with --test-threads=1 if flaky. 7 tests total (6 new), bringing backend tests from 54 to 60. Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Add static mutex lock pattern to FirmwareService tests following the established PASSWORD_FILE_LOCK pattern from password service. This allows clear_data_folder tests to run safely in parallel without race conditions on the shared data directory. Changes: - Add DATA_FOLDER_LOCK static mutex for test isolation - Add lock_for_test() method for acquiring test lock - Update three clear_data_folder tests to acquire lock - Remove warning about requiring --test-threads=1 Tests now pass reliably in parallel without any special flags. Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Document the refactoring of firmware service tests to support parallel execution using the mutex lock pattern. Tests now run safely without requiring --test-threads=1 flag. Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
…ce-tests Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
ada1821 to
ffc3c59
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expand firmware service test coverage to validate file cleanup operations and device service client delegation.
Tests now support parallel execution using mutex lock pattern (refactored from initial implementation).
Tests Added (6 new, 7 total)
clear_data_folder (3 tests)
load_update (2 tests)
run_update (2 tests)
Implementation Details
mockallto mockDeviceServiceClientfor async operationsserde_jsonto constructRunUpdate(private fields)DATA_FOLDER_LOCKmutex following thePASSWORD_FILE_LOCKpattern for test isolationRefactoring for Parallel Execution
Initially,
clear_data_foldertests had a race condition due to shared temp directory fromAppConfig. This has been resolved by:DATA_FOLDER_LOCKmutex (following password.rs pattern)lock_for_test()method toFirmwareService--test-threads=1flagKnown Limitations
File Upload Not Tested:
handle_uploaded_firmwareis not tested as it requires mockingactix_multipart::form::tempfile::TempFile, which is complex.Test Results
All 7 tests pass ✅
Impact
Checklist
cargo fmtSigned-off-by: Jan Zachmann 50990105+JanZachmann@users.noreply.github.com