//! NAT Coverage Tests //! //! Tests for network/nat.zig using mock STUN/TURN servers. //! Exercises NAT traversal code paths without external dependencies. const std = @import("std"); const testing = std.testing; const mem = std.mem; const network = @import("network"); const StunClient = network.nat.StunClient; const StunServer = network.nat.StunServer; const TurnClient = network.nat.TurnClient; const TurnServer = network.nat.TurnServer; const HolePuncher = network.nat.HolePuncher; const NatType = network.nat.NatType; const core = @import("core"); const Address = core.Address; const Socket = core.Socket; const Error = core.errors.Error; const mock = @import("helpers").mock_stun_server; const MockStunServer = mock.MockStunServer; // ============================================================================ // StunClient Tests with Mock Server // ============================================================================ test "StunClient: discoverMappedAddress with mock server" { // Start mock STUN server var mock_server = MockStunServer.init(testing.allocator); defer mock_server.deinit(); const mock_port = mock_server.start() catch |err| { std.debug.print("Mock server start failed: {}\n", .{err}); return error.SkipZigTest; }; // Set a specific response address mock_server.setResponseAddress(Address.ipv4(.{ 198, 51, 100, 50 }, 54321)); // Create client socket const client_socket = testing.allocator.create(Socket) catch return error.SkipZigTest; defer { client_socket.deinit(); testing.allocator.destroy(client_socket); } client_socket.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; // Bind to any port client_socket.bind(Address.ipv4(.{ 0, 0, 0, 0 }, 0)) catch return error.SkipZigTest; // Create custom STUN server list pointing to mock const mock_stun_server = StunServer{ .host = "127.0.0.1", .port = mock_port, }; const servers = [_]StunServer{mock_stun_server}; // Create STUN client with mock server var stun_client = StunClient.initWithServers(testing.allocator, client_socket, &servers); // Discover mapped address const mapped = stun_client.discoverMappedAddress() catch |err| { std.debug.print("discoverMappedAddress failed: {}\n", .{err}); return error.SkipZigTest; }; // Verify we got the mock response try testing.expect(mapped.address.port == 54321 or mapped.address.port > 0); try testing.expect(mock_server.getRequestCount() > 0); } test "StunClient: timeout when server doesn't respond" { // Start mock server but disable responses var mock_server = MockStunServer.init(testing.allocator); defer mock_server.deinit(); const mock_port = mock_server.start() catch |err| { std.debug.print("Mock server start failed: {}\n", .{err}); return error.SkipZigTest; }; mock_server.setShouldRespond(false); // Create client socket const client_socket = testing.allocator.create(Socket) catch return error.SkipZigTest; defer { client_socket.deinit(); testing.allocator.destroy(client_socket); } client_socket.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; client_socket.bind(Address.ipv4(.{ 0, 0, 0, 0 }, 0)) catch return error.SkipZigTest; const mock_stun_server = StunServer{ .host = "127.0.0.1", .port = mock_port, }; const servers = [_]StunServer{mock_stun_server}; var stun_client = StunClient.initWithServers(testing.allocator, client_socket, &servers); // Should fail with timeout since server won't respond const result = stun_client.discoverMappedAddress(); if (result) |_| { // Might succeed if there's a fallback } else |_| { // Expected - timeout } // Verify server received requests try testing.expect(mock_server.getRequestCount() > 0); } // ============================================================================ // StunClient Unit Tests (no network) // ============================================================================ test "StunClient: init with default servers" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const client = StunClient.init(testing.allocator, sock); _ = client; // Just verify init doesn't crash } test "StunClient: initWithServers custom list" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const servers = [_]StunServer{ .{ .host = "stun1.example.com", .port = 3478 }, .{ .host = "stun2.example.com", .port = 3479 }, }; const client = StunClient.initWithServers(testing.allocator, sock, &servers); _ = client; } // ============================================================================ // NatType Tests // ============================================================================ test "NatType: enum values" { const types = [_]NatType{ .unknown, .open_internet, .full_cone, .restricted_cone, .port_restricted_cone, .symmetric, }; for (types) |t| { try testing.expect(@intFromEnum(t) < 10); } } // ============================================================================ // HolePuncher Tests // ============================================================================ test "HolePuncher: init" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const puncher = HolePuncher.init(testing.allocator, sock); _ = puncher; } test "HolePuncher: initWithStunServers" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const servers = [_]StunServer{ .{ .host = "stun.example.com", .port = 3478 }, }; const puncher = HolePuncher.initWithStunServers(testing.allocator, sock, &servers); _ = puncher; } // ============================================================================ // TurnClient Tests // ============================================================================ test "TurnClient: init" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const turn_server = TurnServer{ .host = "turn.example.com", .port = 3478, .username = "user", .credential = "pass", }; var client = TurnClient.init(testing.allocator, sock, turn_server); defer client.deinit(); } test "TurnClient: hasValidAllocation returns false initially" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const turn_server = TurnServer{ .host = "turn.example.com", .port = 3478, .username = "user", .credential = "pass", }; var client = TurnClient.init(testing.allocator, sock, turn_server); defer client.deinit(); try testing.expect(!client.hasValidAllocation()); } test "TurnClient: getRelayedAddress returns null without allocation" { const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer testing.allocator.destroy(sock); sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; defer sock.deinit(); const turn_server = TurnServer{ .host = "turn.example.com", .port = 3478, .username = "user", .credential = "pass", }; var client = TurnClient.init(testing.allocator, sock, turn_server); defer client.deinit(); try testing.expect(client.getRelayedAddress() == null); } // ============================================================================ // STUN Message Parsing Tests // ============================================================================ test "STUN: parseXorMappedAddress valid response" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; // Build a valid STUN response manually var response: [64]u8 = undefined; // Header std.mem.writeInt(u16, response[0..2], mock.STUN_BINDING_RESPONSE, .big); std.mem.writeInt(u16, response[2..4], 12, .big); // attr length std.mem.writeInt(u32, response[4..8], mock.STUN_MAGIC_COOKIE, .big); @memcpy(response[8..20], &transaction_id); // XOR-MAPPED-ADDRESS attribute std.mem.writeInt(u16, response[20..22], mock.STUN_ATTR_XOR_MAPPED_ADDRESS, .big); std.mem.writeInt(u16, response[22..24], 8, .big); response[24] = 0; // reserved response[25] = 0x01; // IPv4 // XOR'd port: 12345 ^ 0x2112 = 0x2E6F std.mem.writeInt(u16, response[26..28], 12345 ^ 0x2112, .big); // XOR'd address: 192.168.1.100 ^ magic cookie bytes const magic_bytes = std.mem.toBytes(std.mem.nativeToBig(u32, mock.STUN_MAGIC_COOKIE)); response[28] = 192 ^ magic_bytes[0]; response[29] = 168 ^ magic_bytes[1]; response[30] = 1 ^ magic_bytes[2]; response[31] = 100 ^ magic_bytes[3]; const addr = mock.parseXorMappedAddress(response[0..32], &transaction_id); try testing.expect(addr != null); if (addr) |a| { try testing.expectEqual(@as(u16, 12345), a.port); // Access IPv4 bytes directly if (a.family == .ipv4) { const bytes = a.data.ipv4.bytes; try testing.expectEqual(@as(u8, 192), bytes[0]); try testing.expectEqual(@as(u8, 168), bytes[1]); try testing.expectEqual(@as(u8, 1), bytes[2]); try testing.expectEqual(@as(u8, 100), bytes[3]); } } } test "STUN: parseXorMappedAddress wrong transaction ID" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; const wrong_id = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var response: [64]u8 = undefined; std.mem.writeInt(u16, response[0..2], mock.STUN_BINDING_RESPONSE, .big); std.mem.writeInt(u16, response[2..4], 0, .big); std.mem.writeInt(u32, response[4..8], mock.STUN_MAGIC_COOKIE, .big); @memcpy(response[8..20], &wrong_id); const addr = mock.parseXorMappedAddress(response[0..20], &transaction_id); try testing.expect(addr == null); } test "STUN: parseXorMappedAddress wrong magic cookie" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var response: [64]u8 = undefined; std.mem.writeInt(u16, response[0..2], mock.STUN_BINDING_RESPONSE, .big); std.mem.writeInt(u16, response[2..4], 0, .big); std.mem.writeInt(u32, response[4..8], 0x12345678, .big); // Wrong magic @memcpy(response[8..20], &transaction_id); const addr = mock.parseXorMappedAddress(response[0..20], &transaction_id); try testing.expect(addr == null); } test "STUN: parseXorMappedAddress truncated response" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var response: [10]u8 = undefined; // Too short const addr = mock.parseXorMappedAddress(&response, &transaction_id); try testing.expect(addr == null); } test "STUN: buildStunBindingRequest" { var buffer: [64]u8 = undefined; const transaction_id = [_]u8{ 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; const len = mock.buildStunBindingRequest(&buffer, &transaction_id); try testing.expectEqual(@as(usize, 20), len); try testing.expectEqual(mock.STUN_BINDING_REQUEST, std.mem.readInt(u16, buffer[0..2], .big)); try testing.expectEqual(@as(u16, 0), std.mem.readInt(u16, buffer[2..4], .big)); // No attributes try testing.expectEqual(mock.STUN_MAGIC_COOKIE, std.mem.readInt(u32, buffer[4..8], .big)); try testing.expect(std.mem.eql(u8, buffer[8..20], &transaction_id)); } // ============================================================================ // Edge Cases // ============================================================================ test "StunServer: struct initialization" { const server = StunServer{ .host = "stun.example.com", .port = 3478, }; try testing.expectEqualStrings("stun.example.com", server.host); try testing.expectEqual(@as(u16, 3478), server.port); } test "TurnServer: struct initialization with credentials" { const server = TurnServer{ .host = "turn.example.com", .port = 3478, .username = "testuser", .credential = "testpass", }; try testing.expectEqualStrings("turn.example.com", server.host); try testing.expectEqual(@as(u16, 3478), server.port); // Access optional fields with .? try testing.expectEqualStrings("testuser", server.username.?); try testing.expectEqualStrings("testpass", server.credential.?); } // ============================================================================ // NatType Method Tests // ============================================================================ test "NatType: traversalDifficulty values" { try testing.expectEqual(@as(u8, 255), NatType.unknown.traversalDifficulty()); try testing.expectEqual(@as(u8, 0), NatType.open_internet.traversalDifficulty()); try testing.expectEqual(@as(u8, 1), NatType.full_cone.traversalDifficulty()); try testing.expectEqual(@as(u8, 2), NatType.restricted_cone.traversalDifficulty()); try testing.expectEqual(@as(u8, 3), NatType.port_restricted_cone.traversalDifficulty()); try testing.expectEqual(@as(u8, 4), NatType.symmetric.traversalDifficulty()); } test "NatType: canTraverse" { try testing.expect(!NatType.unknown.canTraverse()); try testing.expect(NatType.open_internet.canTraverse()); try testing.expect(NatType.full_cone.canTraverse()); try testing.expect(NatType.restricted_cone.canTraverse()); try testing.expect(NatType.port_restricted_cone.canTraverse()); try testing.expect(!NatType.symmetric.canTraverse()); } // ============================================================================ // TurnAllocation Tests // ============================================================================ test "TurnAllocation: isExpired when fresh" { const allocation = network.nat.TurnAllocation{ .relayed_address = Address.ipv4(.{ 192, 168, 1, 1 }, 12345), .lifetime = 600, // 10 minutes .created_at = std.time.timestamp(), .transaction_id = [_]u8{0} ** 12, }; try testing.expect(!allocation.isExpired()); } test "TurnAllocation: isExpired when old" { const allocation = network.nat.TurnAllocation{ .relayed_address = Address.ipv4(.{ 192, 168, 1, 1 }, 12345), .lifetime = 10, // 10 seconds .created_at = std.time.timestamp() - 20, // Created 20 seconds ago .transaction_id = [_]u8{0} ** 12, }; try testing.expect(allocation.isExpired()); } test "TurnAllocation: remainingLifetime" { const now = std.time.timestamp(); const allocation = network.nat.TurnAllocation{ .relayed_address = Address.ipv4(.{ 192, 168, 1, 1 }, 12345), .lifetime = 600, .created_at = now - 100, // 100 seconds ago .transaction_id = [_]u8{0} ** 12, }; const remaining = allocation.remainingLifetime(); try testing.expect(remaining <= 500); try testing.expect(remaining >= 400); } // ============================================================================ // MappedAddress Format Tests // ============================================================================ test "MappedAddress: format IPv4" { const mapped = network.nat.MappedAddress{ .address = Address.ipv4(.{ 192, 168, 1, 100 }, 12345), .port = 12345, }; var buffer: [256]u8 = undefined; var stream = std.io.fixedBufferStream(&buffer); mapped.format(stream.writer()) catch {}; const output = stream.getWritten(); try testing.expect(output.len > 0); } // ============================================================================ // Endpoint Format Tests // ============================================================================ test "Endpoint: format" { const endpoint = network.nat.Endpoint{ .local_addr = Address.ipv4(.{ 192, 168, 1, 10 }, 5000), .local_port = 5000, .public_addr = Address.ipv4(.{ 203, 0, 113, 50 }, 54321), .public_port = 54321, }; var buffer: [256]u8 = undefined; var stream = std.io.fixedBufferStream(&buffer); endpoint.format(stream.writer()) catch {}; const output = stream.getWritten(); try testing.expect(output.len > 0); } // ============================================================================ // HolePuncher with Mock Server // ============================================================================ test "HolePuncher: discoverEndpoint with mock server" { // Start mock STUN server var mock_server = MockStunServer.init(testing.allocator); defer mock_server.deinit(); const mock_port = mock_server.start() catch |err| { std.debug.print("Mock server start failed: {}\n", .{err}); return error.SkipZigTest; }; mock_server.setResponseAddress(Address.ipv4(.{ 203, 0, 113, 100 }, 44444)); // Create socket const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer { sock.deinit(); testing.allocator.destroy(sock); } sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; sock.bind(Address.ipv4(.{ 0, 0, 0, 0 }, 0)) catch return error.SkipZigTest; const servers = [_]StunServer{.{ .host = "127.0.0.1", .port = mock_port }}; var puncher = HolePuncher.initWithStunServers(testing.allocator, sock, &servers); const endpoint = puncher.discoverEndpoint() catch |err| { std.debug.print("discoverEndpoint failed: {}\n", .{err}); return error.SkipZigTest; }; try testing.expect(endpoint.public_port > 0); } // ============================================================================ // StunClient: detectNatType Tests // ============================================================================ test "StunClient: detectNatType with mock server" { var mock_server = MockStunServer.init(testing.allocator); defer mock_server.deinit(); const mock_port = mock_server.start() catch |err| { std.debug.print("Mock server start failed: {}\n", .{err}); return error.SkipZigTest; }; // Set response to match local address (simulating open internet) mock_server.setResponseAddress(Address.ipv4(.{ 127, 0, 0, 1 }, 0)); const sock = testing.allocator.create(Socket) catch return error.SkipZigTest; defer { sock.deinit(); testing.allocator.destroy(sock); } sock.* = Socket.init(.udp, testing.allocator) catch return error.SkipZigTest; sock.bind(Address.ipv4(.{ 0, 0, 0, 0 }, 0)) catch return error.SkipZigTest; const servers = [_]StunServer{.{ .host = "127.0.0.1", .port = mock_port }}; var stun_client = StunClient.initWithServers(testing.allocator, sock, &servers); const nat_type = stun_client.detectNatType() catch |err| { std.debug.print("detectNatType failed: {}\n", .{err}); return error.SkipZigTest; }; // Should detect some NAT type (may vary depending on network) _ = nat_type; } // ============================================================================ // STUN Message Parsing Edge Cases // ============================================================================ test "STUN: parseXorMappedAddress IPv6" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var response: [64]u8 = undefined; // Header std.mem.writeInt(u16, response[0..2], mock.STUN_BINDING_RESPONSE, .big); std.mem.writeInt(u16, response[2..4], 24, .big); // attr length (4 + 20) std.mem.writeInt(u32, response[4..8], mock.STUN_MAGIC_COOKIE, .big); @memcpy(response[8..20], &transaction_id); // XOR-MAPPED-ADDRESS attribute for IPv6 std.mem.writeInt(u16, response[20..22], mock.STUN_ATTR_XOR_MAPPED_ADDRESS, .big); std.mem.writeInt(u16, response[22..24], 20, .big); // Length: 20 bytes for IPv6 response[24] = 0; // reserved response[25] = 0x02; // IPv6 family // XOR'd port std.mem.writeInt(u16, response[26..28], 12345 ^ 0x2112, .big); // XOR'd IPv6 address (16 bytes) const magic_bytes = std.mem.toBytes(std.mem.nativeToBig(u32, mock.STUN_MAGIC_COOKIE)); var ipv6_addr: [16]u8 = .{ 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 }; // XOR first 4 bytes with magic cookie for (0..4) |i| { ipv6_addr[i] ^= magic_bytes[i]; } // XOR remaining 12 bytes with transaction ID for (0..12) |i| { ipv6_addr[4 + i] ^= transaction_id[i]; } @memcpy(response[28..44], &ipv6_addr); const addr = mock.parseXorMappedAddress(response[0..44], &transaction_id); // May or may not succeed depending on implementation details _ = addr; } test "STUN: parseXorMappedAddress unknown family" { const transaction_id = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var response: [64]u8 = undefined; std.mem.writeInt(u16, response[0..2], mock.STUN_BINDING_RESPONSE, .big); std.mem.writeInt(u16, response[2..4], 12, .big); std.mem.writeInt(u32, response[4..8], mock.STUN_MAGIC_COOKIE, .big); @memcpy(response[8..20], &transaction_id); std.mem.writeInt(u16, response[20..22], mock.STUN_ATTR_XOR_MAPPED_ADDRESS, .big); std.mem.writeInt(u16, response[22..24], 8, .big); response[24] = 0; response[25] = 0x99; // Unknown family std.mem.writeInt(u16, response[26..28], 12345, .big); @memset(response[28..32], 0); const addr = mock.parseXorMappedAddress(response[0..32], &transaction_id); try testing.expect(addr == null); } // ============================================================================ // TurnServer Tests // ============================================================================ test "TurnServer: default port" { const server = TurnServer{ .host = "turn.example.com", }; try testing.expectEqual(@as(u16, 3478), server.port); try testing.expect(server.username == null); try testing.expect(server.credential == null); } // ============================================================================ // DEFAULT_STUN_SERVERS Tests // ============================================================================ test "DEFAULT_STUN_SERVERS: are defined" { const servers = network.nat.DEFAULT_STUN_SERVERS; try testing.expect(servers.len > 0); // Verify first server has expected structure try testing.expect(servers[0].host.len > 0); try testing.expect(servers[0].port > 0); } // ============================================================================ // ChannelBinding Tests // ============================================================================ test "ChannelBinding: isExpired" { const now = std.time.timestamp(); // Create expired binding (created long ago with short lifetime) const expired = network.nat.ChannelBinding{ .channel_number = 0x4000, .peer_address = Address.ipv4(.{ 10, 0, 0, 10 }, 5000), .created_at = now - 700, // Created 700 seconds ago .lifetime = 600, // Only valid for 600 seconds }; try testing.expect(expired.isExpired()); // Create valid binding (created recently) const valid = network.nat.ChannelBinding{ .channel_number = 0x4001, .peer_address = Address.ipv4(.{ 10, 0, 0, 11 }, 5001), .created_at = now - 100, // Created 100 seconds ago .lifetime = 600, // Valid for 600 seconds }; try testing.expect(!valid.isExpired()); } // ============================================================================ // StunServer Tests // ============================================================================ test "StunServer: with custom port" { const server = StunServer{ .host = "stun.example.com", .port = 3479, }; try testing.expectEqual(@as(u16, 3479), server.port); } // ============================================================================ // TurnServer Tests // ============================================================================ test "TurnServer: with credentials" { const server = TurnServer{ .host = "turn.example.com", .port = 3478, .username = "testuser", .credential = "testpass", }; try testing.expectEqual(@as(u16, 3478), server.port); try testing.expectEqualStrings("testuser", server.username.?); try testing.expectEqualStrings("testpass", server.credential.?); } // ============================================================================ // DEFAULT_TURN_SERVERS Tests // ============================================================================ test "DEFAULT_TURN_SERVERS: are defined" { const servers = network.nat.DEFAULT_TURN_SERVERS; // May be empty if no default TURN servers configured _ = servers.len; } // ============================================================================ // Mock TurnClient Tests // ============================================================================ test "MockTurnClient: basic operations" { const MockSocket = core.MockSocket; const MockTurnClient = network.nat.MockTurnClient; var mock_socket = MockSocket.init(testing.allocator); defer mock_socket.deinit(); const turn_server = TurnServer{ .host = "127.0.0.1", .port = 3478, .username = "test", .credential = "test", }; var client = MockTurnClient.init(testing.allocator, &mock_socket, turn_server); defer client.deinit(); // Test getRelayedAddress without allocation try testing.expect(client.getRelayedAddress() == null); // Test hasValidAllocation without allocation try testing.expect(!client.hasValidAllocation()); } // ============================================================================ // Mock StunClient Tests // ============================================================================ test "MockStunClient: initialization" { const MockSocket = core.MockSocket; const MockStunClient = network.nat.MockStunClient; var mock_socket = MockSocket.init(testing.allocator); defer mock_socket.deinit(); const client = MockStunClient.init(testing.allocator, &mock_socket); _ = client; } test "MockStunClient: initWithServers" { const MockSocket = core.MockSocket; const MockStunClient = network.nat.MockStunClient; var mock_socket = MockSocket.init(testing.allocator); defer mock_socket.deinit(); const servers = [_]StunServer{ .{ .host = "stun1.example.com", .port = 3478 }, .{ .host = "stun2.example.com", .port = 3479 }, }; const client = MockStunClient.initWithServers(testing.allocator, &mock_socket, &servers); _ = client; } // ============================================================================ // Mock HolePuncher Tests // ============================================================================ test "MockHolePuncher: initialization" { const MockSocket = core.MockSocket; const MockHolePuncher = network.nat.MockHolePuncher; var mock_socket = MockSocket.init(testing.allocator); defer mock_socket.deinit(); const puncher = MockHolePuncher.init(testing.allocator, &mock_socket); _ = puncher; } test "MockHolePuncher: initWithStunServers" { const MockSocket = core.MockSocket; const MockHolePuncher = network.nat.MockHolePuncher; var mock_socket = MockSocket.init(testing.allocator); defer mock_socket.deinit(); const servers = [_]StunServer{ .{ .host = "stun.example.com", .port = 3478 }, }; const puncher = MockHolePuncher.initWithStunServers(testing.allocator, &mock_socket, &servers); _ = puncher; }