@@ -88,12 +88,231 @@ struct OFREPIntegrationTests {
88
88
reason: . error,
89
89
variant: " a "
90
90
)
91
- let flag = " static-a-b "
91
+ let flag = " static-a "
92
92
await #expect( provider. resolution ( of: flag, defaultValue: defaultValue, context: nil ) == resolution)
93
93
}
94
94
}
95
95
}
96
96
97
+ @Suite ( " String Flag Resolution " )
98
+ struct StringResolutionTests {
99
+ @Test ( " Static " , arguments: [ ( " static-a " , " a " , " value-a " ) , ( " static-b " , " b " , " value-b " ) ] )
100
+ func staticBool( flag: String , variant: String , expectedValue: String ) async throws {
101
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
102
+
103
+ try await withOFREPProvider ( provider) {
104
+ let resolution = OpenFeatureResolution (
105
+ value: expectedValue,
106
+ error: nil ,
107
+ reason: . static,
108
+ variant: variant,
109
+ flagMetadata: [ : ]
110
+ )
111
+ await #expect( provider. resolution ( of: flag, defaultValue: " default " , context: nil ) == resolution)
112
+ }
113
+ }
114
+
115
+ @Test ( " Targeting Match " )
116
+ func targetingMatch( ) async throws {
117
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
118
+
119
+ try await withOFREPProvider ( provider) {
120
+ let resolution = OpenFeatureResolution (
121
+ value: " value-b " ,
122
+ error: nil ,
123
+ reason: . targetingMatch,
124
+ variant: " b " ,
125
+ flagMetadata: [ : ]
126
+ )
127
+ let flag = " targeting-b "
128
+ let context = OpenFeatureEvaluationContext ( targetingKey: " swift " )
129
+ await #expect( provider. resolution ( of: flag, defaultValue: " default " , context: context) == resolution)
130
+ }
131
+ }
132
+
133
+ @Test ( " No Targeting Match " )
134
+ func noTargetingMatch( ) async throws {
135
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
136
+
137
+ try await withOFREPProvider ( provider) {
138
+ let resolution = OpenFeatureResolution (
139
+ value: " value-a " ,
140
+ error: nil ,
141
+ reason: . default,
142
+ variant: " a " ,
143
+ flagMetadata: [ : ]
144
+ )
145
+ let flag = " targeting-b "
146
+ await #expect( provider. resolution ( of: flag, defaultValue: " default " , context: nil ) == resolution)
147
+ }
148
+ }
149
+
150
+ @Test ( " Type mismatch " )
151
+ func typeMismatch( ) async throws {
152
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
153
+
154
+ try await withOFREPProvider ( provider) {
155
+ let resolution = OpenFeatureResolution (
156
+ value: " default " ,
157
+ error: OpenFeatureResolutionError (
158
+ code: . typeMismatch,
159
+ message: #"Expected flag value of type "String" but received "Bool"."#
160
+ ) ,
161
+ reason: . error,
162
+ variant: " on "
163
+ )
164
+ let flag = " static-on "
165
+ await #expect( provider. resolution ( of: flag, defaultValue: " default " , context: nil ) == resolution)
166
+ }
167
+ }
168
+ }
169
+
170
+ @Suite ( " Int Flag Resolution " )
171
+ struct IntResolutionTests {
172
+ @Test ( " Static " , arguments: [ ( " static-negative-42 " , " a " , - 42 ) , ( " static-positive-42 " , " b " , 42 ) ] )
173
+ func staticBool( flag: String , variant: String , expectedValue: Int ) async throws {
174
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
175
+
176
+ try await withOFREPProvider ( provider) {
177
+ let resolution = OpenFeatureResolution (
178
+ value: expectedValue,
179
+ error: nil ,
180
+ reason: . static,
181
+ variant: variant,
182
+ flagMetadata: [ : ]
183
+ )
184
+ await #expect( provider. resolution ( of: flag, defaultValue: 0 , context: nil ) == resolution)
185
+ }
186
+ }
187
+
188
+ @Test ( " Targeting Match " )
189
+ func targetingMatch( ) async throws {
190
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
191
+
192
+ try await withOFREPProvider ( provider) {
193
+ let resolution = OpenFeatureResolution (
194
+ value: 42 ,
195
+ error: nil ,
196
+ reason: . targetingMatch,
197
+ variant: " b " ,
198
+ flagMetadata: [ : ]
199
+ )
200
+ let flag = " targeting-42 "
201
+ let context = OpenFeatureEvaluationContext ( targetingKey: " swift " )
202
+ await #expect( provider. resolution ( of: flag, defaultValue: 0 , context: context) == resolution)
203
+ }
204
+ }
205
+
206
+ @Test ( " No Targeting Match " )
207
+ func noTargetingMatch( ) async throws {
208
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
209
+
210
+ try await withOFREPProvider ( provider) {
211
+ let resolution = OpenFeatureResolution (
212
+ value: - 42 ,
213
+ error: nil ,
214
+ reason: . default,
215
+ variant: " a " ,
216
+ flagMetadata: [ : ]
217
+ )
218
+ let flag = " targeting-42 "
219
+ await #expect( provider. resolution ( of: flag, defaultValue: 0 , context: nil ) == resolution)
220
+ }
221
+ }
222
+
223
+ @Test ( " Type mismatch " )
224
+ func typeMismatch( ) async throws {
225
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
226
+
227
+ try await withOFREPProvider ( provider) {
228
+ let resolution = OpenFeatureResolution (
229
+ value: 42 ,
230
+ error: OpenFeatureResolutionError (
231
+ code: . typeMismatch,
232
+ message: #"Expected flag value of type "Int" but received "String"."#
233
+ ) ,
234
+ reason: . error,
235
+ variant: " a "
236
+ )
237
+ let flag = " static-a "
238
+ await #expect( provider. resolution ( of: flag, defaultValue: 42 , context: nil ) == resolution)
239
+ }
240
+ }
241
+ }
242
+
243
+ @Suite ( " Double Flag Resolution " )
244
+ struct DoubleResolutionTests {
245
+ @Test ( " Static " , arguments: [ ( " static-negative-42.123 " , " a " , - 42.123 ) , ( " static-positive-42.123 " , " b " , 42.123 ) ] )
246
+ func staticBool( flag: String , variant: String , expectedValue: Double ) async throws {
247
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
248
+
249
+ try await withOFREPProvider ( provider) {
250
+ let resolution = OpenFeatureResolution (
251
+ value: expectedValue,
252
+ error: nil ,
253
+ reason: . static,
254
+ variant: variant,
255
+ flagMetadata: [ : ]
256
+ )
257
+ await #expect( provider. resolution ( of: flag, defaultValue: 0.0 , context: nil ) == resolution)
258
+ }
259
+ }
260
+
261
+ @Test ( " Targeting Match " )
262
+ func targetingMatch( ) async throws {
263
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
264
+
265
+ try await withOFREPProvider ( provider) {
266
+ let resolution = OpenFeatureResolution (
267
+ value: 42.123 ,
268
+ error: nil ,
269
+ reason: . targetingMatch,
270
+ variant: " b " ,
271
+ flagMetadata: [ : ]
272
+ )
273
+ let flag = " targeting-42.123 "
274
+ let context = OpenFeatureEvaluationContext ( targetingKey: " swift " )
275
+ await #expect( provider. resolution ( of: flag, defaultValue: 0.0 , context: context) == resolution)
276
+ }
277
+ }
278
+
279
+ @Test ( " No Targeting Match " )
280
+ func noTargetingMatch( ) async throws {
281
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
282
+
283
+ try await withOFREPProvider ( provider) {
284
+ let resolution = OpenFeatureResolution (
285
+ value: - 42.123 ,
286
+ error: nil ,
287
+ reason: . default,
288
+ variant: " a " ,
289
+ flagMetadata: [ : ]
290
+ )
291
+ let flag = " targeting-42.123 "
292
+ await #expect( provider. resolution ( of: flag, defaultValue: 0.0 , context: nil ) == resolution)
293
+ }
294
+ }
295
+
296
+ @Test ( " Type mismatch " )
297
+ func typeMismatch( ) async throws {
298
+ let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
299
+
300
+ try await withOFREPProvider ( provider) {
301
+ let resolution = OpenFeatureResolution (
302
+ value: 42.123 ,
303
+ error: OpenFeatureResolutionError (
304
+ code: . typeMismatch,
305
+ message: #"Expected flag value of type "Double" but received "String"."#
306
+ ) ,
307
+ reason: . error,
308
+ variant: " a "
309
+ )
310
+ let flag = " static-a "
311
+ await #expect( provider. resolution ( of: flag, defaultValue: 42.123 , context: nil ) == resolution)
312
+ }
313
+ }
314
+ }
315
+
97
316
@Test ( " Flag not found " , arguments: [ true , false ] )
98
317
func flagNotFound( defaultValue: Bool ) async throws {
99
318
let provider = OFREPProvider ( serverURL: URL ( string: " http://localhost:8016 " ) !)
0 commit comments