Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Jan 16, 2025
1 parent d1d9c42 commit 8c594e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
10 changes: 4 additions & 6 deletions Tests/GRPCNIOTransportHTTP2Tests/ControlService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,19 @@ extension ControlService {
}

private func serverRemotePeerInfo(context: ServerContext) -> String {
"Server's remote peer: \(context.peer)"
context.peer
}

private func serverLocalPeerInfo(context: ServerContext) -> String {
"Server's local peer: <not yet implemented>"
"<not yet implemented>"
}

private func clientRemotePeerInfo<T>(request: StreamingServerRequest<T>) -> String {
let remotePeer = request.metadata[stringValues: "remotePeer"].first(where: { _ in true })!
return "Client's remote peer: \(remotePeer)"
request.metadata[stringValues: "remotePeer"].first(where: { _ in true })!
}

private func clientLocalPeerInfo<T>(request: StreamingServerRequest<T>) -> String {
let localPeer = request.metadata[stringValues: "localPeer"].first(where: { _ in true })!
return "Client's local peer: \(localPeer)"
request.metadata[stringValues: "localPeer"].first(where: { _ in true })!
}

private func handle(
Expand Down
46 changes: 12 additions & 34 deletions Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1633,22 +1633,18 @@ final class HTTP2TransportTests: XCTestCase {
) { control, _, _ in
let peerInfo = try await control.peerInfo()

let serverRemotePeerMatches = peerInfo.server.remote.wholeMatch(
of: /Server's remote peer: ipv4:127.0.0.1:(\d+)/
)
let serverRemotePeerMatches = peerInfo.server.remote.wholeMatch(of: /ipv4:127\.0\.0\.1:(\d+)/)
let clientPort = try XCTUnwrap(serverRemotePeerMatches).1

// TODO: Uncomment when server local peer info is implemented

// let serverLocalPeerMatches = peerInfo.server.local.wholeMatch(of: /Server's local peer: <not yet implemented>/)
// let serverLocalPeerMatches = peerInfo.server.local.wholeMatch(of: /<not yet implemented>/)
// let serverPort = XCTUnwrap(serverLocalPeerMatches).1

// let clientRemotePeerMatches = peerInfo.client.remote.wholeMatch(of: /Client's remote peer: ipv4:127.0.0.1:(\d+)/)
// let clientRemotePeerMatches = peerInfo.client.remote.wholeMatch(of: /ipv4:127.0.0.1:(\d+)/)
// XCTAssertEqual(try XCTUnwrap(clientRemotePeerMatches).1, serverPort)

let clientLocalPeerMatches = peerInfo.client.local.wholeMatch(
of: /Client's local peer: ipv4:127.0.0.1:(\d+)/
)
let clientLocalPeerMatches = peerInfo.client.local.wholeMatch(of: /ipv4:127\.0\.0\.1:(\d+)/)
XCTAssertEqual(try XCTUnwrap(clientLocalPeerMatches).1, clientPort)
}
}
Expand All @@ -1659,22 +1655,18 @@ final class HTTP2TransportTests: XCTestCase {
) { control, _, _ in
let peerInfo = try await control.peerInfo()

let serverRemotePeerMatches = peerInfo.server.remote.wholeMatch(
of: /Server's remote peer: ipv6:[::1]:(\d+)/
)
let serverRemotePeerMatches = peerInfo.server.remote.wholeMatch(of: /ipv6:\[::1\]:(\d+)/)
let clientPort = try XCTUnwrap(serverRemotePeerMatches).1

// TODO: Uncomment when server local peer info is implemented

// let serverLocalPeerMatches = peerInfo.server.local.wholeMatch(of: /Server's local peer: <not yet implemented>/)
// let serverLocalPeerMatches = peerInfo.server.local.wholeMatch(of: /<not yet implemented>/)
// let serverPort = XCTUnwrap(serverLocalPeerMatches).1

// let clientRemotePeerMatches = peerInfo.client.remote.wholeMatch(of: /Client's remote peer: ipv6:[::1]:(\d+)/)
// let clientRemotePeerMatches = peerInfo.client.remote.wholeMatch(of: /ipv6:\[::1\]:(\d+)/)
// XCTAssertEqual(try XCTUnwrap(clientRemotePeerMatches).1, serverPort)

let clientLocalPeerMatches = peerInfo.client.local.wholeMatch(
of: /Client's local peer: ipv6:[::1]:(\d+)/
)
let clientLocalPeerMatches = peerInfo.client.local.wholeMatch(of: /ipv6:\[::1\]:(\d+)/)
XCTAssertEqual(try XCTUnwrap(clientLocalPeerMatches).1, clientPort)
}
}
Expand All @@ -1686,25 +1678,11 @@ final class HTTP2TransportTests: XCTestCase {
) { control, _, _ in
let peerInfo = try await control.peerInfo()

let serverRemotePeerMatches = peerInfo.server.remote.wholeMatch(
of: /Server's remote peer: unix:peer-info-uds/
)
XCTAssertNotNil(serverRemotePeerMatches)

let serverLocalPeerMatches = peerInfo.server.local.wholeMatch(
of: /Server's local peer: <not yet implemented>/
)
XCTAssertNotNil(serverLocalPeerMatches)
XCTAssertNotNil(peerInfo.server.remote.wholeMatch(of: /unix:peer-info-uds/))
XCTAssertNotNil(peerInfo.server.local.wholeMatch(of: /<not yet implemented>/))

let clientRemotePeerMatches = peerInfo.client.remote.wholeMatch(
of: /Client's remote peer: unix:peer-info-uds/
)
XCTAssertNotNil(clientRemotePeerMatches)

let clientLocalPeerMatches = peerInfo.client.local.wholeMatch(
of: /Client's local peer: unix:peer-info-uds/
)
XCTAssertNotNil(clientLocalPeerMatches)
XCTAssertNotNil(peerInfo.client.remote.wholeMatch(of: /unix:peer-info-uds/))
XCTAssertNotNil(peerInfo.client.local.wholeMatch(of: /unix:peer-info-uds/))
}
}
}
Expand Down

0 comments on commit 8c594e9

Please sign in to comment.