From bd4cf7890d489b970ec76295fa5ffbf80c39b16e Mon Sep 17 00:00:00 2001 From: Nathan Harris Date: Wed, 9 Jan 2019 18:13:47 -0800 Subject: [PATCH] Update unit test references for new type names and to cover more test cases --- .../Commands/BasicCommandsTests.swift | 4 +- Tests/NIORedisTests/NIORedisTests.swift | 27 ---------- Tests/NIORedisTests/RedisDriverTests.swift | 50 +++++++++++++++++++ ...neTests.swift => RedisPipelineTests.swift} | 13 ++--- Tests/NIORedisTests/XCTestManifests.swift | 4 +- 5 files changed, 61 insertions(+), 37 deletions(-) delete mode 100644 Tests/NIORedisTests/NIORedisTests.swift create mode 100644 Tests/NIORedisTests/RedisDriverTests.swift rename Tests/NIORedisTests/{NIORedisPipelineTests.swift => RedisPipelineTests.swift} (88%) diff --git a/Tests/NIORedisTests/Commands/BasicCommandsTests.swift b/Tests/NIORedisTests/Commands/BasicCommandsTests.swift index e3a548b..ec49425 100644 --- a/Tests/NIORedisTests/Commands/BasicCommandsTests.swift +++ b/Tests/NIORedisTests/Commands/BasicCommandsTests.swift @@ -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 { diff --git a/Tests/NIORedisTests/NIORedisTests.swift b/Tests/NIORedisTests/NIORedisTests.swift deleted file mode 100644 index 8781859..0000000 --- a/Tests/NIORedisTests/NIORedisTests.swift +++ /dev/null @@ -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), - ] -} diff --git a/Tests/NIORedisTests/RedisDriverTests.swift b/Tests/NIORedisTests/RedisDriverTests.swift new file mode 100644 index 0000000..029ec8d --- /dev/null +++ b/Tests/NIORedisTests/RedisDriverTests.swift @@ -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), + ] +} diff --git a/Tests/NIORedisTests/NIORedisPipelineTests.swift b/Tests/NIORedisTests/RedisPipelineTests.swift similarity index 88% rename from Tests/NIORedisTests/NIORedisPipelineTests.swift rename to Tests/NIORedisTests/RedisPipelineTests.swift index 8d6d789..b81fbc6 100644 --- a/Tests/NIORedisTests/NIORedisPipelineTests.swift +++ b/Tests/NIORedisTests/RedisPipelineTests.swift @@ -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 { diff --git a/Tests/NIORedisTests/XCTestManifests.swift b/Tests/NIORedisTests/XCTestManifests.swift index 4633259..f8f3148 100644 --- a/Tests/NIORedisTests/XCTestManifests.swift +++ b/Tests/NIORedisTests/XCTestManifests.swift @@ -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