@@ -17,6 +17,7 @@ class GoFeatureFlagProviderTests: XCTestCase {
17
17
options: GoFeatureFlagProviderOptions (
18
18
endpoint: " https://localhost:1031 " ,
19
19
dataFlushInterval: 1 ,
20
+ exporterMetadata: [ " version " : ExporterMetadataValue . string ( " 1.0.0 " ) ] ,
20
21
networkService: mockNetworkService
21
22
)
22
23
)
@@ -34,11 +35,72 @@ class GoFeatureFlagProviderTests: XCTestCase {
34
35
35
36
let expectation = self . expectation ( description: " Waiting for delay " )
36
37
37
- DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + 1 .0) { expectation. fulfill ( ) }
38
- await fulfillment ( of: [ expectation] , timeout: 2 .0)
38
+ DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + 2 .0) { expectation. fulfill ( ) }
39
+ await fulfillment ( of: [ expectation] , timeout: 3 .0)
39
40
40
41
XCTAssertEqual ( 1 , mockNetworkService. dataCollectorCallCounter)
41
42
XCTAssertEqual ( 6 , mockNetworkService. dataCollectorEventCounter)
43
+
44
+ do {
45
+ let httpBodyCollector = mockNetworkService. requests [ mockNetworkService. requests. count - 1 ] . httpBody!
46
+ // print httpBodyCollector
47
+ print ( String ( data: httpBodyCollector, encoding: . utf8) !)
48
+ let json = try JSONSerialization . jsonObject ( with: httpBodyCollector, options: [ ] ) as? [ String : Any ]
49
+ guard let jsonDict = json else {
50
+ XCTFail ( " Could not deserialize JSON " )
51
+ return
52
+ }
53
+ } catch {
54
+ XCTFail ( " Error deserializing JSON: \( error) " )
55
+ }
56
+
57
+ }
58
+
59
+ func testExporterMetadata( ) async {
60
+ let mockNetworkService = MockNetworkingService ( mockStatus: 200 )
61
+ let provider = GoFeatureFlagProvider (
62
+ options: GoFeatureFlagProviderOptions (
63
+ endpoint: " https://localhost:1031 " ,
64
+ dataFlushInterval: 1 ,
65
+ exporterMetadata: [ " version " : ExporterMetadataValue . string ( " 1.0.0 " ) , " testInt " : ExporterMetadataValue . integer ( 123 ) , " testDouble " : ExporterMetadataValue . double ( 123.45 ) ] ,
66
+ networkService: mockNetworkService
67
+ )
68
+ )
69
+ let evaluationCtx = MutableContext ( targetingKey: " ede04e44-463d-40d1-8fc0-b1d6855578d0 " )
70
+ let api = OpenFeatureAPI ( )
71
+ await api. setProviderAndWait ( provider: provider, initialContext: evaluationCtx)
72
+ let client = api. getClient ( )
73
+
74
+ _ = client. getBooleanDetails ( key: " my-flag " , defaultValue: false )
75
+ _ = client. getBooleanDetails ( key: " my-flag " , defaultValue: false )
76
+ _ = client. getIntegerDetails ( key: " int-flag " , defaultValue: 1 )
77
+ _ = client. getDoubleDetails ( key: " double-flag " , defaultValue: 1.0 )
78
+ _ = client. getStringDetails ( key: " string-flag " , defaultValue: " default " )
79
+ _ = client. getObjectDetails ( key: " object-flag " , defaultValue: Value . null)
80
+
81
+ let expectation = self . expectation ( description: " Waiting for delay " )
82
+
83
+ DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + 2.0 ) { expectation. fulfill ( ) }
84
+ await fulfillment ( of: [ expectation] , timeout: 3.0 )
85
+
86
+ XCTAssertEqual ( 1 , mockNetworkService. dataCollectorCallCounter)
87
+ XCTAssertEqual ( 6 , mockNetworkService. dataCollectorEventCounter)
88
+
89
+ do {
90
+ let httpBodyCollector = mockNetworkService. requests [ mockNetworkService. requests. count - 1 ] . httpBody!
91
+ let decodedStruct = try JSONDecoder ( ) . decode ( DataCollectorRequest . self, from: httpBodyCollector)
92
+ let want = [
93
+ " version " : ExporterMetadataValue . string ( " 1.0.0 " ) ,
94
+ " testDouble " : ExporterMetadataValue . double ( 123.45 ) ,
95
+ " testInt " : ExporterMetadataValue . integer ( 123 ) ,
96
+ " openfeature " : ExporterMetadataValue . bool ( true ) ,
97
+ " provider " : ExporterMetadataValue . string ( " swift " )
98
+ ] as? [ String : ExporterMetadataValue ]
99
+ XCTAssertEqual ( want, decodedStruct. meta)
100
+ } catch {
101
+ XCTFail ( " Error deserializing: \( error) " )
102
+ }
103
+
42
104
}
43
105
44
106
func testProviderMultipleHookCall( ) async {
0 commit comments