@@ -17,15 +17,9 @@ import NIO
1717import XCTest
1818
1919final class EtcdClientTests : XCTestCase {
20- var eventLoopGroup : EventLoopGroup !
21- var etcdClient : EtcdClient !
22-
23- override func setUp( ) async throws {
24- eventLoopGroup = MultiThreadedEventLoopGroup . singleton
25- etcdClient = EtcdClient ( host: " localhost " , port: 2379 , eventLoopGroup: eventLoopGroup)
26- }
27-
2820 func testSetAndGetStringValue( ) async throws {
21+ let etcdClient = EtcdClient . testClient
22+
2923 try await etcdClient. set ( " testKey " , value: " testValue " )
3024 let key = " testKey " . data ( using: . utf8) !
3125 let rangeRequest = RangeRequest ( key: key)
@@ -36,13 +30,17 @@ final class EtcdClientTests: XCTestCase {
3630 }
3731
3832 func testGetNonExistentKey( ) async throws {
33+ let etcdClient = EtcdClient . testClient
34+
3935 let key = " nonExistentKey " . data ( using: . utf8) !
4036 let rangeRequest = RangeRequest ( key: key)
4137 let result = try await etcdClient. getRange ( rangeRequest)
4238 XCTAssertNil ( result)
4339 }
4440
4541 func testDeleteKeyExists( ) async throws {
42+ let etcdClient = EtcdClient . testClient
43+
4644 let key = " testKey "
4745 let value = " testValue "
4846 try await etcdClient. set ( key, value: value)
@@ -60,6 +58,8 @@ final class EtcdClientTests: XCTestCase {
6058 }
6159
6260 func testDeleteNonExistentKey( ) async throws {
61+ let etcdClient = EtcdClient . testClient
62+
6363 let key = " testKey " . data ( using: . utf8) !
6464 let rangeRequest = RangeRequest ( key: key)
6565
@@ -74,6 +74,8 @@ final class EtcdClientTests: XCTestCase {
7474 }
7575
7676 func testUpdateExistingKey( ) async throws {
77+ let etcdClient = EtcdClient . testClient
78+
7779 let key = " testKey "
7880 let value = " testValue "
7981 try await etcdClient. set ( key, value: value)
@@ -95,14 +97,16 @@ final class EtcdClientTests: XCTestCase {
9597 }
9698
9799 func testWatch( ) async throws {
100+ let etcdClient = EtcdClient . testClient
101+
98102 let key = " testKey "
99103 let value = " testValue " . data ( using: . utf8) !
100104
101105 try await etcdClient. put ( key, value: " foo " )
102106
103107 try await withThrowingTaskGroup ( of: Void . self) { group in
104108 group. addTask {
105- try await self . etcdClient. watch ( key) { watchAsyncSequence in
109+ try await etcdClient. watch ( key) { watchAsyncSequence in
106110 var iterator = watchAsyncSequence. makeAsyncIterator ( )
107111 let events = try await iterator. next ( )
108112 guard let events = events else {
@@ -122,8 +126,16 @@ final class EtcdClientTests: XCTestCase {
122126 }
123127
124128 try await Task . sleep ( nanoseconds: 1_000_000_000 )
125- try await self . etcdClient. put ( key, value: String ( data: value, encoding: . utf8) !)
129+ try await etcdClient. put ( key, value: String ( data: value, encoding: . utf8) !)
126130 group. cancelAll ( )
127131 }
128132 }
129133}
134+
135+ extension EtcdClient {
136+ fileprivate static let testClient = EtcdClient (
137+ host: " localhost " ,
138+ port: 2379 ,
139+ eventLoopGroup: . singletonMultiThreadedEventLoopGroup
140+ )
141+ }
0 commit comments