Skip to content

Commit e7b4486

Browse files
tests: Rename tests IntegrationTests only run if enabled
1 parent 3e46c2d commit e7b4486

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Tests/ETCDTests/ETCDTests.swift renamed to Tests/IntegrationTests/IntegrationTests.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ import ETCD
1616
import NIO
1717
import XCTest
1818

19-
final class EtcdClientTests: XCTestCase {
19+
final class IntegrationTests: XCTestCase {
20+
21+
private static let integrationTestEnabled = getBoolEnv("SWIFT_ETCD_CLIENT_INTEGRATION_TEST_ENABLED") ?? false
22+
23+
override func setUp() async throws {
24+
try XCTSkipUnless(Self.integrationTestEnabled)
25+
}
26+
2027
func testSetAndGetStringValue() async throws {
2128
let etcdClient = EtcdClient.testClient
2229

@@ -134,8 +141,19 @@ final class EtcdClientTests: XCTestCase {
134141

135142
extension EtcdClient {
136143
fileprivate static let testClient = EtcdClient(
137-
host: "localhost",
138-
port: 2379,
144+
host: ProcessInfo.processInfo.environment["ETCD_HOST"] ?? "localhost",
145+
port: getIntEnv("ETCD_PORT") ?? 2379,
139146
eventLoopGroup: .singletonMultiThreadedEventLoopGroup
140147
)
141148
}
149+
150+
/// Returns true if `key` is a truthy string, otherwise returns false.
151+
private func getBoolEnv(_ key: String) -> Bool? {
152+
switch ProcessInfo.processInfo.environment[key]?.lowercased() {
153+
case .none: return nil
154+
case "true", "y", "yes", "on", "1": return true
155+
default: return false
156+
}
157+
}
158+
159+
private func getIntEnv(_ key: String) -> Int? { ProcessInfo.processInfo.environment[key].flatMap(Int.init(_:)) }

0 commit comments

Comments
 (0)