@@ -947,7 +947,7 @@ func TestGetFeatureFlagPayload(t *testing.T) {
947
947
948
948
func TestGetRemoteConfigPayload (t * testing.T ) {
949
949
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
950
- w .Write ([]byte (fixture ("test-remote-config.json" )))
950
+ w .Write ([]byte (fixture ("test-remote-config.json" )))
951
951
}))
952
952
953
953
defer server .Close ()
@@ -971,7 +971,6 @@ func TestGetRemoteConfigPayload(t *testing.T) {
971
971
}
972
972
}
973
973
974
-
975
974
func TestFlagWithVariantOverrides (t * testing.T ) {
976
975
977
976
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -4646,3 +4645,71 @@ func TestFetchFlagsFails(t *testing.T) {
4646
4645
t .Error ("Expected to be called" , expectedCalls , "times but got" , actualCalls )
4647
4646
}
4648
4647
}
4648
+
4649
+ func TestFeatureFlagWithFalseVariant (t * testing.T ) {
4650
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
4651
+ if strings .HasPrefix (r .URL .Path , "/api/feature_flag/local_evaluation" ) {
4652
+ w .Write ([]byte (`{
4653
+ "flags": [{
4654
+ "id": 719,
4655
+ "name": "",
4656
+ "key": "test-flag",
4657
+ "filters": {
4658
+ "groups": [
4659
+ {
4660
+ "properties": [],
4661
+ "rollout_percentage": 100
4662
+ }
4663
+ ],
4664
+ "multivariate": {
4665
+ "variants": [
4666
+ {"key": "false", "rollout_percentage": 50},
4667
+ {"key": "true", "rollout_percentage": 50}
4668
+ ]
4669
+ }
4670
+ },
4671
+ "deleted": false,
4672
+ "active": true,
4673
+ "is_simple_flag": false,
4674
+ "rollout_percentage": null
4675
+ }]
4676
+ }` ))
4677
+ }
4678
+ }))
4679
+ defer server .Close ()
4680
+
4681
+ client , _ := NewWithConfig ("Csyjlnlun3OzyNJAafdlv" , Config {
4682
+ PersonalApiKey : "some very secret key" ,
4683
+ Endpoint : server .URL ,
4684
+ })
4685
+ defer client .Close ()
4686
+
4687
+ // Test GetFeatureFlag - should return the variant name "false"
4688
+ variant , err := client .GetFeatureFlag (
4689
+ FeatureFlagPayload {
4690
+ Key : "test-flag" ,
4691
+ DistinctId : "test-id" ,
4692
+ },
4693
+ )
4694
+ if err != nil {
4695
+ t .Error ("Unexpected error:" , err )
4696
+ }
4697
+ if variant != "false" {
4698
+ t .Errorf ("Expected variant 'false', got: %v" , variant )
4699
+ }
4700
+
4701
+ // Test IsFeatureEnabled - should return the variant name "false"
4702
+ // This will fail with the current implementation because it incorrectly converts "false" to false
4703
+ isEnabled , err := client .IsFeatureEnabled (
4704
+ FeatureFlagPayload {
4705
+ Key : "test-flag" ,
4706
+ DistinctId : "test-id" ,
4707
+ },
4708
+ )
4709
+ if err != nil {
4710
+ t .Error ("Unexpected error:" , err )
4711
+ }
4712
+ if isEnabled != "false" {
4713
+ t .Errorf ("Expected variant 'false', got: %v" , isEnabled )
4714
+ }
4715
+ }
0 commit comments