Skip to content

Commit 8cf5b32

Browse files
committed
adding project config support
1 parent 69a0d5a commit 8cf5b32

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

pkg/config/datafileprojectconfig/entities/entities.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type FeatureFlag struct {
6969
Key string `json:"key"`
7070
ExperimentIDs []string `json:"experimentIds"`
7171
Variables []Variable `json:"variables"`
72+
HoldoutIDs []string `json:"holdoutIds"`
7273
}
7374

7475
// Variable represents a Variable object from the Optimizely datafile

pkg/config/datafileprojectconfig/mappers/feature.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func MapFeatures(featureFlags []datafileEntities.FeatureFlag, rolloutMap map[str
6262
feature.ExperimentIDs = featureFlag.ExperimentIDs
6363
feature.FeatureExperiments = featureExperiments
6464
feature.VariableMap = variableMap
65+
feature.HoldoutIDs = featureFlag.HoldoutIDs
6566
featureMap[featureFlag.Key] = feature
6667
}
6768
return featureMap

pkg/config/datafileprojectconfig/mappers/feature_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func TestMapFeatures(t *testing.T) {
6767
Rollout: rollout,
6868
FeatureExperiments: []entities.Experiment{experiment31111},
6969
VariableMap: map[string]entities.Variable{variable.Key: variable},
70+
HoldoutIDs: []string(nil),
7071
},
7172
}
7273
expectedExperimentMap := map[string]entities.Experiment{
@@ -77,3 +78,37 @@ func TestMapFeatures(t *testing.T) {
7778
assert.Equal(t, expectedFeatureMap, featureMap)
7879
assert.Equal(t, expectedExperimentMap, experimentMap)
7980
}
81+
82+
func TestMapFeaturesWithHoldoutIds(t *testing.T) {
83+
const testFeatureFlagString = `{
84+
"id": "22222",
85+
"key": "test_feature_22222",
86+
"rolloutId": "42222",
87+
"experimentIds": ["32222"],
88+
"variables": [{"defaultValue":"test","id":"2","key":"var","type":"string"}],
89+
"holdoutIds": ["holdout_1", "holdout_2"]
90+
}`
91+
92+
var rawFeatureFlag datafileEntities.FeatureFlag
93+
var json = jsoniter.ConfigCompatibleWithStandardLibrary
94+
json.Unmarshal([]byte(testFeatureFlagString), &rawFeatureFlag)
95+
96+
rawFeatureFlags := []datafileEntities.FeatureFlag{rawFeatureFlag}
97+
rollout := entities.Rollout{ID: "42222"}
98+
rolloutMap := map[string]entities.Rollout{
99+
"42222": rollout,
100+
}
101+
experiment32222 := entities.Experiment{ID: "32222"}
102+
experimentMap := map[string]entities.Experiment{
103+
"32222": experiment32222,
104+
}
105+
featureMap := MapFeatures(rawFeatureFlags, rolloutMap, experimentMap)
106+
107+
// Verify that holdoutIds are properly mapped
108+
feature := featureMap["test_feature_22222"]
109+
expectedHoldoutIds := []string{"holdout_1", "holdout_2"}
110+
111+
assert.Equal(t, expectedHoldoutIds, feature.HoldoutIDs)
112+
assert.Equal(t, "22222", feature.ID)
113+
assert.Equal(t, "test_feature_22222", feature.Key)
114+
}

pkg/entities/feature.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Feature struct {
2525
ExperimentIDs []string
2626
Rollout Rollout
2727
VariableMap map[string]Variable
28+
HoldoutIDs []string
2829
}
2930

3031
// Rollout represents a feature rollout

0 commit comments

Comments
 (0)