@@ -256,57 +256,6 @@ func TestCaptureNoProperties(t *testing.T) {
256
256
})
257
257
}
258
258
259
- func ExampleHistoricalMigrationCapture () {
260
- body , server := mockServer ()
261
- defer server .Close ()
262
-
263
- client , _ := NewWithConfig ("Csyjlnlun3OzyNJAafdlv" , Config {
264
- Endpoint : server .URL ,
265
- BatchSize : 1 ,
266
- now : mockTime ,
267
- HistoricalMigration : true ,
268
- })
269
- defer client .Close ()
270
-
271
- client .Enqueue (Capture {
272
- Event : "Download" ,
273
- DistinctId : "123456" ,
274
- Properties : Properties {
275
- "application" : "PostHog Go" ,
276
- "version" : "1.0.0" ,
277
- "platform" : "macos" , // :)
278
- },
279
- SendFeatureFlags : false ,
280
- })
281
-
282
- fmt .Printf ("%s\n " , <- body )
283
- // Output:
284
- // {
285
- // "api_key": "Csyjlnlun3OzyNJAafdlv",
286
- // "batch": [
287
- // {
288
- // "distinct_id": "123456",
289
- // "event": "Download",
290
- // "library": "posthog-go",
291
- // "library_version": "1.0.0",
292
- // "properties": {
293
- // "$lib": "posthog-go",
294
- // "$lib_version": "1.0.0",
295
- // "application": "PostHog Go",
296
- // "platform": "macos",
297
- // "version": "1.0.0"
298
- // },
299
- // "send_feature_flags": false,
300
- // "timestamp": "2009-11-10T23:00:00Z",
301
- // "type": "capture",
302
- // "uuid": ""
303
- // }
304
- // ],
305
- // "historical_migration": true
306
- // }
307
-
308
- }
309
-
310
259
func TestEnqueue (t * testing.T ) {
311
260
tests := map [string ]struct {
312
261
ref string
@@ -1780,3 +1729,121 @@ func TestCaptureSendFlags(t *testing.T) {
1780
1729
t .Fatal (err )
1781
1730
}
1782
1731
}
1732
+
1733
+ func TestFeatureFlagQuotaLimits (t * testing.T ) {
1734
+ t .Run ("decide endpoint quota limited" , func (t * testing.T ) {
1735
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1736
+ if strings .HasPrefix (r .URL .Path , "/decide" ) {
1737
+ w .WriteHeader (http .StatusOK )
1738
+ w .Write ([]byte (`{
1739
+ "featureFlags": {"test-flag": true},
1740
+ "featureFlagPayloads": {"test-flag": "test-payload"},
1741
+ "quota_limited": ["feature_flags"]
1742
+ }` ))
1743
+ }
1744
+ }))
1745
+ defer server .Close ()
1746
+
1747
+ client , _ := NewWithConfig ("test-api-key" , Config {
1748
+ Endpoint : server .URL ,
1749
+ })
1750
+ defer client .Close ()
1751
+
1752
+ // Test GetFeatureFlag
1753
+ value , err := client .GetFeatureFlag (FeatureFlagPayload {
1754
+ Key : "test-flag" ,
1755
+ DistinctId : "user123" ,
1756
+ })
1757
+ if err != nil {
1758
+ t .Error ("Expected no error, got" , err )
1759
+ }
1760
+ if value != false {
1761
+ t .Error ("Expected false when quota limited, got" , value )
1762
+ }
1763
+
1764
+ // Test GetFeatureFlagPayload
1765
+ payload , err := client .GetFeatureFlagPayload (FeatureFlagPayload {
1766
+ Key : "test-flag" ,
1767
+ DistinctId : "user123" ,
1768
+ })
1769
+ if err != nil {
1770
+ t .Error ("Expected no error, got" , err )
1771
+ }
1772
+ if payload != "" {
1773
+ t .Error ("Expected empty string when quota limited, got" , payload )
1774
+ }
1775
+
1776
+ // Test GetAllFlags
1777
+ flags , err := client .GetAllFlags (FeatureFlagPayloadNoKey {
1778
+ DistinctId : "user123" ,
1779
+ })
1780
+ if err != nil {
1781
+ t .Error ("Expected no error, got" , err )
1782
+ }
1783
+ if len (flags ) != 0 {
1784
+ t .Error ("Expected empty map when quota limited, got" , flags )
1785
+ }
1786
+ })
1787
+
1788
+ t .Run ("local evaluation endpoint quota limited" , func (t * testing.T ) {
1789
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1790
+ if strings .HasPrefix (r .URL .Path , "/api/feature_flag/local_evaluation" ) {
1791
+ w .WriteHeader (http .StatusPaymentRequired )
1792
+ w .Write ([]byte (`{
1793
+ "type": "quota_limited",
1794
+ "detail": "You have exceeded your feature flag request quota",
1795
+ "code": "payment_required"
1796
+ }` ))
1797
+ } else if strings .HasPrefix (r .URL .Path , "/decide" ) {
1798
+ // Mock the decide endpoint as well since it's used as fallback
1799
+ w .WriteHeader (http .StatusOK )
1800
+ w .Write ([]byte (`{
1801
+ "featureFlags": {},
1802
+ "featureFlagPayloads": {}
1803
+ }` ))
1804
+ }
1805
+ }))
1806
+ defer server .Close ()
1807
+
1808
+ client , _ := NewWithConfig ("test-api-key" , Config {
1809
+ PersonalApiKey : "test-personal-key" ,
1810
+ Endpoint : server .URL ,
1811
+ })
1812
+ defer client .Close ()
1813
+
1814
+ // Test GetFeatureFlag
1815
+ value , err := client .GetFeatureFlag (FeatureFlagPayload {
1816
+ Key : "test-flag" ,
1817
+ DistinctId : "user123" ,
1818
+ })
1819
+ if err != nil {
1820
+ t .Error ("Expected no error, got" , err )
1821
+ }
1822
+ if value != false {
1823
+ t .Error ("Expected false when quota limited, got" , value )
1824
+ }
1825
+
1826
+ // Test GetFeatureFlagPayload
1827
+ payload , err := client .GetFeatureFlagPayload (FeatureFlagPayload {
1828
+ Key : "test-flag" ,
1829
+ DistinctId : "user123" ,
1830
+ })
1831
+ if err != nil {
1832
+ t .Error ("Expected no error, got" , err )
1833
+ }
1834
+ if payload != "" {
1835
+ t .Error ("Expected empty string when quota limited, got" , payload )
1836
+ }
1837
+
1838
+ // Test GetAllFlags
1839
+ flags , err := client .GetAllFlags (FeatureFlagPayloadNoKey {
1840
+ DistinctId : "user123" ,
1841
+ })
1842
+ if err != nil {
1843
+ t .Error ("Expected no error, got" , err )
1844
+ }
1845
+ if len (flags ) != 0 {
1846
+ t .Error ("Expected empty map when quota limited, got" , flags )
1847
+ }
1848
+ })
1849
+ }
0 commit comments