File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -102,4 +102,23 @@ public final class EtcdClient: @unchecked Sendable {
102
102
public func delete( _ key: String ) async throws {
103
103
return try await delete ( key. utf8)
104
104
}
105
+
106
+ /// Puts a value for a specified key in the ETCD server. If the key does not exist, a new key, value pair is created.
107
+ ///
108
+ /// - Parameters:
109
+ /// - key: The key for which the value is to be put. Parameter is of type Sequence<UInt8>.
110
+ /// - value: The ETCD value to put for the key. Parameter is of type Sequence<UInt8>.
111
+ public func put( _ key: some Sequence < UInt8 > , value: some Sequence < UInt8 > ) async throws {
112
+ try await set ( key, value: value)
113
+ }
114
+
115
+ /// Puts a value for a specified key in the ETCD server. If the key does not exist, a new key, value pair is created.
116
+ ///
117
+ /// - Parameters:
118
+ /// - key: The key for which the value is to be put. Parameter is of type String.
119
+ /// - value: The ETCD value to put for the key. Parameter is of type String.
120
+ public func put( _ key: String , value: String ) async throws {
121
+ try await put ( key. utf8, value: value. utf8)
122
+ }
123
+
105
124
}
Original file line number Diff line number Diff line change @@ -62,4 +62,21 @@ final class EtcdClientTests: XCTestCase {
62
62
fetchedValue = try await etcdClient. get ( key)
63
63
XCTAssertNil ( fetchedValue)
64
64
}
65
+
66
+ func testUpdateExistingKey( ) async throws {
67
+ let key = " testKey "
68
+ let value = " testValue "
69
+ try await etcdClient. set ( key, value: value)
70
+
71
+ let fetchedValue = try await etcdClient. get ( key)
72
+ XCTAssertNotNil ( fetchedValue)
73
+ XCTAssertEqual ( String ( data: fetchedValue!, encoding: . utf8) , value)
74
+
75
+ let updatedValue = " updatedValue "
76
+ try await etcdClient. put ( key, value: updatedValue)
77
+
78
+ let fetchedUpdatedValue = try await etcdClient. get ( key)
79
+ XCTAssertNotNil ( fetchedUpdatedValue)
80
+ XCTAssertEqual ( String ( data: fetchedUpdatedValue!, encoding: . utf8) , updatedValue)
81
+ }
65
82
}
You can’t perform that action at this time.
0 commit comments