mirror of
https://github.com/swift-server/RediStack.git
synced 2026-06-02 07:37:33 +00:00
Update unit test references for new type names and to cover more test cases
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
import XCTest
|
||||
|
||||
final class BasicCommandsTests: XCTestCase {
|
||||
private let redis = NIORedis(executionModel: .spawnThreads(1))
|
||||
private let redis = RedisDriver(executionModel: .spawnThreads(1))
|
||||
deinit { try? redis.terminate() }
|
||||
|
||||
private var connection: NIORedisConnection?
|
||||
private var connection: RedisConnection?
|
||||
|
||||
override func setUp() {
|
||||
do {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
@testable import NIORedis
|
||||
import XCTest
|
||||
|
||||
final class NIORedisTests: XCTestCase {
|
||||
func test_makeConnection() {
|
||||
let redis = NIORedis(executionModel: .spawnThreads(1))
|
||||
defer { try? redis.terminate() }
|
||||
|
||||
XCTAssertNoThrow(try redis.makeConnection().wait().close())
|
||||
}
|
||||
|
||||
func test_command() throws {
|
||||
let redis = NIORedis(executionModel: .spawnThreads(1))
|
||||
defer { try? redis.terminate() }
|
||||
|
||||
let connection = try redis.makeConnection().wait()
|
||||
let result = try connection.command("SADD", [.bulkString("key".convertedToData()), try 3.convertToRESP()]).wait()
|
||||
XCTAssertNotNil(result.int)
|
||||
XCTAssertEqual(result.int, 1)
|
||||
try connection.command("DEL", [.bulkString("key".convertedToData())]).wait()
|
||||
connection.close()
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("test_makeConnection", test_makeConnection),
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
@testable import NIORedis
|
||||
import XCTest
|
||||
|
||||
final class RedisDriverTests: XCTestCase {
|
||||
private var driver: RedisDriver!
|
||||
private var connection: RedisConnection!
|
||||
|
||||
override func setUp() {
|
||||
let driver = RedisDriver(executionModel: .spawnThreads(1))
|
||||
|
||||
guard let connection = try? driver.makeConnection().wait() else {
|
||||
return XCTFail("Failed to create a connection!")
|
||||
}
|
||||
|
||||
self.driver = driver
|
||||
self.connection = connection
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
_ = connection.command("FLUSHALL")
|
||||
.then { _ in self.connection.close() }
|
||||
.map { _ in try? self.driver.terminate() }
|
||||
}
|
||||
|
||||
func test_makeConnection() {
|
||||
XCTAssertNoThrow(try driver.makeConnection().wait().close())
|
||||
}
|
||||
|
||||
func test_command_succeeds() throws {
|
||||
let result = try connection.command(
|
||||
"SADD",
|
||||
arguments: [.bulkString("key".convertedToData()), try 3.convertToRESP()
|
||||
]).wait()
|
||||
|
||||
XCTAssertNotNil(result.int)
|
||||
XCTAssertEqual(result.int, 1)
|
||||
}
|
||||
|
||||
func test_command_fails() {
|
||||
let command = connection.command("GET")
|
||||
|
||||
XCTAssertThrowsError(try command.wait())
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("test_makeConnection", test_makeConnection),
|
||||
("test_command_succeeds", test_command_succeeds),
|
||||
("test_command_fails", test_command_fails),
|
||||
]
|
||||
}
|
||||
+7
-6
@@ -1,12 +1,12 @@
|
||||
@testable import NIORedis
|
||||
import XCTest
|
||||
|
||||
final class NIORedisPipelineTests: XCTestCase {
|
||||
private var redis: NIORedis!
|
||||
private var connection: NIORedisConnection!
|
||||
final class RedisPipelineTests: XCTestCase {
|
||||
private var redis: RedisDriver!
|
||||
private var connection: RedisConnection!
|
||||
|
||||
override func setUp() {
|
||||
let redis = NIORedis(executionModel: .spawnThreads(2))
|
||||
let redis = RedisDriver(executionModel: .spawnThreads(2))
|
||||
|
||||
guard let connection = try? redis.makeConnection().wait() else {
|
||||
return XCTFail("Failed to create connection!")
|
||||
@@ -30,10 +30,11 @@ final class NIORedisPipelineTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_executeFails() throws {
|
||||
let pipeline = try connection.makePipeline()
|
||||
let future = try connection.makePipeline()
|
||||
.enqueue(command: "GET")
|
||||
.execute()
|
||||
|
||||
XCTAssertThrowsError(try pipeline.execute().wait())
|
||||
XCTAssertThrowsError(try future.wait())
|
||||
}
|
||||
|
||||
func test_singleCommand() throws {
|
||||
@@ -3,14 +3,14 @@ import XCTest
|
||||
#if !os(macOS)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(NIORedisTests.allTests),
|
||||
testCase(RedisDriverTests.allTests),
|
||||
testCase(RESPDecoderTests.allTests),
|
||||
testCase(RESPDecoderParsingTests.allTests),
|
||||
testCase(RESPDecoderByteToMessageDecoderTests.allTests),
|
||||
testCase(RESPEncoderTests.allTests),
|
||||
testCase(RESPEncoderParsingTests.allTests),
|
||||
testCase(BasicCommandsTests.allTests),
|
||||
testCase(NIORedisPipelineTests.allTests)
|
||||
testCase(RedisPipelineTests.allTests)
|
||||
]
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user