Skip to content

Commit

Permalink
Merge pull request #4 from vkill/feature/add-tests
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
helje5 authored Jun 9, 2018
2 parents 35a408e + a31aca0 commit 1a55bd2
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ let package = Package(
],
targets: [
.target(name: "NIORedis", dependencies: [ "NIO", "NIOFoundationCompat" ]),
.target(name: "Redis", dependencies: [ "NIORedis" ])
.target(name: "Redis", dependencies: [ "NIORedis" ]),
.testTarget(name: "NIORedisTests", dependencies: [ "NIORedis"]),
.testTarget(name: "RedisTests", dependencies: [ "Redis"]),
]
)
9 changes: 9 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

import NIORedisTests
import RedisTests

var tests = [XCTestCaseEntry]()
tests += NIORedisTests.allTests()
tests += RedisTests.allTests()
XCTMain(tests)
12 changes: 12 additions & 0 deletions Tests/NIORedisTests/RESPValueTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
@testable import NIORedis

final class RESPValueTests: XCTestCase {
func testDescription() throws {
XCTAssert(String(describing: RESPValue(1)) == "1")
}

static var allTests = [
("testDescription", testDescription)
]
}
9 changes: 9 additions & 0 deletions Tests/NIORedisTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

#if !os(macOS)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(RESPValueTests.allTests),
]
}
#endif
32 changes: 32 additions & 0 deletions Tests/RedisTests/RedisClientTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import XCTest
@testable import Redis
import NIO

final class RedisClientTests: XCTestCase {
func testCreateClientWithDefaultArguments() throws {
let redisClient = Redis.createClient()

XCTAssert(redisClient.options.hostname! == "127.0.0.1")
XCTAssert(redisClient.options.port == 6379)
XCTAssert(redisClient.options.password == nil)
XCTAssert(redisClient.options.database == nil)
}

func testCreateClientWithSpecifiedArguments() throws {
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next()

let redisClient = Redis.createClient(port: 6380, host: "localhost", password: "password", db: 1, eventLoopGroup: eventLoop)

XCTAssert(redisClient.options.hostname! == "localhost")
XCTAssert(redisClient.options.port == 6380)
XCTAssert(redisClient.options.password == "password")
XCTAssert(redisClient.options.database == 1)
XCTAssert(redisClient.options.eventLoopGroup === eventLoop)
XCTAssert(redisClient.eventLoop === eventLoop)
}

static var allTests = [
("testCreateClientWithDefaultArguments", testCreateClientWithDefaultArguments),
("testCreateClientWithSpecifiedArguments", testCreateClientWithSpecifiedArguments),
]
}
9 changes: 9 additions & 0 deletions Tests/RedisTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

#if !os(macOS)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(RedisClientTests.allTests),
]
}
#endif

0 comments on commit 1a55bd2

Please sign in to comment.