Skip to content

Conversation

@JanZachmann
Copy link
Contributor

Summary

Add comprehensive unit tests for NetworkConfigService to validate network configuration logic, INI file generation, and request/response handling.

Tests Added (14)

Validation (6 tests)

  • ✅ Valid DHCP config passes
  • ✅ Valid static IP config passes
  • ✅ Empty interface name fails
  • ✅ Netmask above 32 fails
  • ✅ Netmask at boundary (32) passes
  • ✅ Netmask at zero passes

INI Generation (2 tests)

  • ✅ DHCP mode creates valid systemd-networkd INI
  • ✅ Static IP mode creates valid INI with Address/Gateway/DNS

Rollback Response (3 tests)

  • ✅ Response includes rollback timeout (90s)
  • ✅ Rollback enabled flag set correctly
  • ✅ Rollback disabled flag set correctly

Serialization (3 tests)

  • ✅ NetworkConfig serializes with camelCase
  • ✅ NetworkConfig deserializes from camelCase
  • ✅ Request includes enableRollback field

Implementation Details

  • Uses tempfile for testing INI file generation
  • Replicates production INI generation logic in isolation
  • Tests serde_valid validation rules (min_length, max/min netmask)
  • Validates systemd-networkd format compliance

Limitations

Tests for rollback file I/O operations (create_rollback, process_pending_rollback, cancel_rollback) are not included due to hardcoded filesystem paths:

  • /network/ for network config files
  • /tmp/ for rollback state files

These would require:

  1. Refactoring to inject path dependencies, or
  2. Integration tests with Docker/filesystem mocking

The validation, INI generation, and serialization logic represents the testable subset without architectural changes.

Test Results

cargo test --features mock services::network::tests

All 14 tests pass ✅

Impact

  • Total backend tests: 40 → 54 (+14)
  • Coverage: Network validation & INI generation (rollback I/O excluded)
  • Phase: 1.2 of backend test plan

Checklist

  • All tests pass
  • Code formatted with cargo fmt
  • Clippy passes
  • BACKEND_TEST_CONCEPT.md updated
  • Limitations documented

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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant