-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a mock target and updated README (#8)
* Added a mock target and updated README
- Loading branch information
1 parent
c0112a9
commit f12d4b3
Showing
4 changed files
with
62 additions
and
5 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
51 changes: 51 additions & 0 deletions
51
Sources/AsyncWebSocketClientMocks/AsyncWebSocketClientMock.swift
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,51 @@ | ||
// | ||
// AsyncWebSocketClientMock.swift | ||
// | ||
// | ||
// Created by Henry Javier Serrano Echeverria on 27/1/24. | ||
// | ||
|
||
import AsyncWebSocketClient | ||
import Foundation | ||
|
||
open class AsyncWebSocketClientMock: AsyncWebSocketClientProtocol { | ||
public var connectWasCalledCount = 0 | ||
public func connect() async throws { | ||
connectWasCalledCount += 1 | ||
} | ||
|
||
public var disconnectWasCalledCount = 0 | ||
public func disconnect() async throws { | ||
disconnectWasCalledCount += 1 | ||
} | ||
|
||
public var sendWasCalledStack = [AsyncWebSocketData]() | ||
public func send(_ data: AsyncWebSocketData) async throws { | ||
sendWasCalledStack.append(data) | ||
} | ||
|
||
@Published public var streamSocketEvent = AsyncWebSocketEvent.socketOpened | ||
public var listenStreamWasCalledCount = 0 | ||
public func listenStream() async -> AsyncStream<AsyncWebSocketEvent> { | ||
listenStreamWasCalledCount += 1 | ||
|
||
let stream = $streamSocketEvent.values | ||
return AsyncStream { continuation in | ||
let cancellableTask = Task { | ||
for await event in stream { | ||
try Task.checkCancellation() | ||
continuation.yield(event) | ||
} | ||
} | ||
// Cancel the task that is listening to the stream socket event. | ||
continuation.onTermination = { _ in | ||
cancellableTask.cancel() | ||
} | ||
} | ||
} | ||
|
||
public init() { | ||
|
||
} | ||
|
||
} |