@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "errors"
2222 "fmt"
23+ "strconv"
2324 "sync"
2425 "testing"
2526
@@ -1442,28 +1443,60 @@ func TestGetFeatureDecisionErrFeatureDecision(t *testing.T) {
14421443
14431444func TestGetAllFeatureVariables (t * testing.T ) {
14441445 testFeatureKey := "test_feature_key"
1445- testVariableKey := "test_feature_flag_key"
1446- testVariableValue := "teststring"
14471446 testUserContext := entities.UserContext {ID : "test_user_1" }
1448- testVariationVariable := entities.VariationVariable {
1449- ID : "1" ,
1450- Value : testVariableValue ,
1447+
1448+ type variable struct {
1449+ key string
1450+ defaultVal string
1451+ varVal string
1452+ varType entities.VariableType
1453+ expected interface {}
14511454 }
1452- testVariable := entities.Variable {
1453- DefaultValue : "defaultString" ,
1454- ID : "1" ,
1455- Key : testVariableKey ,
1456- Type : entities .String ,
1455+
1456+ variables := []variable {
1457+ {key : "var_str" , defaultVal : "default" , varVal : "var" , varType : entities .String , expected : "var" },
1458+ {key : "var_bool" , defaultVal : "false" , varVal : "true" , varType : entities .Boolean , expected : true },
1459+ {key : "var_int" , defaultVal : "10" , varVal : "20" , varType : entities .Integer , expected : 20 },
1460+ {key : "var_double" , defaultVal : "1.0" , varVal : "2.0" , varType : entities .Double , expected : 2.0 },
14571461 }
1458- testVariation := getTestVariationWithFeatureVariable (false , testVariationVariable )
1462+
1463+ mockConfig := new (MockProjectConfig )
1464+ variableMap := make (map [string ]entities.Variable )
1465+ varVariableMap := make (map [string ]entities.VariationVariable )
1466+
1467+ for i , v := range variables {
1468+ id := strconv .Itoa (i )
1469+ varVariableMap [id ] = entities.VariationVariable {
1470+ ID : id ,
1471+ Value : v .varVal ,
1472+ }
1473+
1474+ variableMap [id ] = entities.Variable {
1475+ DefaultValue : v .defaultVal ,
1476+ ID : id ,
1477+ Key : v .key ,
1478+ Type : v .varType ,
1479+ }
1480+
1481+ mockConfig .On ("GetVariableByKey" , testFeatureKey , v .key ).Return (v .varVal , nil )
1482+ }
1483+
1484+ testVariation := entities.Variation {
1485+ ID : "22222" ,
1486+ Key : "22222" ,
1487+ FeatureEnabled : true ,
1488+ Variables : varVariableMap ,
1489+ }
1490+
14591491 testVariation .FeatureEnabled = true
14601492 testExperiment := entities.Experiment {
14611493 ID : "111111" ,
14621494 Variations : map [string ]entities.Variation {"22222" : testVariation },
14631495 }
14641496 testFeature := getTestFeature (testFeatureKey , testExperiment )
1465- testFeature .VariableMap = map [string ]entities.Variable {testVariable .Key : testVariable }
1466- mockConfig := getMockConfig (testFeatureKey , testVariableKey , testFeature , testVariable )
1497+ testFeature .VariableMap = variableMap
1498+ mockConfig .On ("GetFeatureByKey" , testFeatureKey ).Return (testFeature , nil )
1499+
14671500 mockConfigManager := new (MockProjectConfigManager )
14681501 mockConfigManager .On ("GetConfig" ).Return (mockConfig , nil )
14691502
@@ -1482,9 +1515,12 @@ func TestGetAllFeatureVariables(t *testing.T) {
14821515 }
14831516
14841517 enabled , variationMap , err := client .GetAllFeatureVariables (testFeatureKey , testUserContext )
1518+ assert .NoError (t , err )
14851519 assert .True (t , enabled )
1486- assert .Equal (t , testVariableValue , variationMap [testVariableKey ])
1487- assert .Nil (t , err )
1520+
1521+ for _ , v := range variables {
1522+ assert .Equal (t , v .expected , variationMap [v .key ])
1523+ }
14881524}
14891525
14901526func TestGetAllFeatureVariablesWithError (t * testing.T ) {
0 commit comments