The wsport test suite ensures the reliability of the WebSocket transport, its integration with the libp2p transport interface, and the accuracy of multiaddr-to-URL conversions. The tests are primarily divided into transport functional tests and address utility validation.
The testing environment leverages standard libp2p test suites and custom helpers to simulate secure and insecure WebSocket connections.
The following diagram illustrates the relationship between the test helpers and the core transport entities:
Testing Entity Map
Sources: websocket_test.go39-117 websocket_test.go145-186
Functional tests for the transport are contained in websocket_test.go. These tests verify the lifecycle of WebSocket connections, including dialing, listening, and multiaddr resolution.
newUpgrader websocket_test.go39-47 and newSecureUpgrader websocket_test.go49-57 to create libp2p upgrader instances with yamux and noise/insecure security transports.TestCanDial websocket_test.go119-142 validates the dialMatcher logic, ensuring the transport correctly identifies supported protocols like /ws, /wss, and /tls/sni/.testWSSServer websocket_test.go145-186 provides a mock secure server to test SNI (Server Name Indication) and TLS handshake success.TestListeningOnDNSAddr addrs_test.go145-155 ensures that listeners can be bound to localhost DNS addresses without losing the domain name information during resolution.For more details on transport lifecycle and TLS testing, see Transport and Listener Tests.
Sources: websocket_test.go119-142 websocket_test.go145-186 addrs_test.go145-155
The address utility tests verify the complex mapping between standard URLs and libp2p multiaddrs, specifically handling the x-parity-ws and x-parity-wss protocols used for path encoding.
Address Mapping Flow
Sources: util_test.go15-79 addrs_test.go12-25 addrs_test.go127-143
TestFromString util_test.go15-79 contains a comprehensive table of test cases mapping standard URLs (e.g., wss://example.com/ws) to their equivalent multiaddrs (e.g., /dns/example.com/tcp/443/x-parity-wss/%2Fws).addrs_test.go like TestMultiaddrWithPathParsing addrs_test.go27-40 ensure that URL paths are correctly extracted from multiaddrs.TestParseWebsocketNetAddr addrs_test.go50-125 validates that the custom Addr type correctly represents various combinations of schemes, hosts, and ports.For detailed tables of supported address formats and conversion logic, see Address Utility Tests.
Sources: util_test.go15-79 addrs_test.go27-40 addrs_test.go50-125
Refresh this wiki