-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for error handling (#16)
### TL;DR Added network output handler with test coverage for initialization and deinitialization ### What changed? - Added network module export in nexlog.zig - Implemented test case for NetworkHandler initialization in network.zig - Created new network_tests.zig file with comprehensive handler testing - Added validation for endpoint configuration and buffer initialization ### How to test? 1. Run the test suite using `zig test` 2. Verify NetworkHandler initialization with example.com:8080 3. Check buffer size and endpoint configuration assertions 4. Confirm proper deinitialization of resources ### Why make this change? To ensure the network output handler is properly tested and validated, providing confidence in its initialization, configuration handling, and resource management. This is crucial for maintaining reliability when sending logs over network connections.
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const std = @import("std"); | ||
const expect = std.testing.expect; | ||
const NetworkHandler = @import("nexlog").output.network.NetworkHandler; | ||
const NetworkConfig = @import("nexlog").output.network.NetworkConfig; | ||
|
||
test "NetworkHandler initialization and deinitialization" { | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
const allocator = gpa.allocator(); | ||
|
||
const config = NetworkConfig{ | ||
.endpoint = .{ | ||
.host = "example.com", | ||
.port = 8080, | ||
.secure = true, | ||
}, | ||
}; | ||
|
||
var handler = try NetworkHandler.init(allocator, config); | ||
defer handler.deinit(); | ||
|
||
try expect(handler.config.endpoint.host.len == config.endpoint.host.len); | ||
try expect(handler.config.endpoint.port == config.endpoint.port); | ||
try expect(handler.circular_buffer.buffer.len == config.buffer_size); | ||
|
||
std.debug.print("NetworkHandler initialized\n", .{}); | ||
} |