Skip to content

Commit b65d358

Browse files
committed
Adding test data. Adjusting for loop. WIP
1 parent 1df8a11 commit b65d358

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

optimizely/decision/composite_feature_service.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ func (f CompositeFeatureService) GetDecision(decisionContext FeatureDecisionCont
4646

4747
// Check if user is bucketed in feature experiment
4848
if f.featureExperimentService != nil && len(feature.FeatureExperiments) > 0 {
49-
// @TODO this can be improved by getting group ID first and determining experiment ID and then bucketing in experiment ID
50-
for idx := 0; idx < len(feature.FeatureExperiments); idx++ {
51-
experiment := feature.FeatureExperiments[idx]
49+
// @TODO this can be improved by getting group ID first and determining experiment and then bucketing in experiment
50+
for _, experiment := range feature.FeatureExperiments {
5251
experimentDecisionContext := ExperimentDecisionContext{
5352
Experiment: &experiment,
5453
ProjectConfig: decisionContext.ProjectConfig,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/****************************************************************************
2+
* Copyright 2019, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* http://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
package decision
18+
19+
import (
20+
"github.com/optimizely/go-sdk/optimizely/entities"
21+
"testing"
22+
)
23+
24+
func TestCompositeFeatureServiceGetDecisionFeatureExperiment(t *testing.T) {
25+
mockProjectConfig := new(mockProjectConfig)
26+
testDecisionContext := FeatureDecisionContext{
27+
Feature: &testFeat3335,
28+
ProjectConfig: mockProjectConfig,
29+
}
30+
31+
testUserContext := entities.UserContext{
32+
ID: "test_user_1",
33+
}
34+
}
35+
36+
func TestCompositeFeatureServiceGetDecisionRollout(t *testing.T) {
37+
38+
}

optimizely/decision/helpers_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,70 @@ var testFeatRollout3334 = entities.Feature{
134134
Experiments: []entities.Experiment{testExp1112},
135135
},
136136
}
137+
138+
// Feature with test and rollout
139+
const testFeat3335Key = "test_feature_3335_key"
140+
// Will use this experiment for feature test
141+
const testExp1113Key = "test_experiment_1113"
142+
var testExp1113Var2223 = entities.Variation{ID: "2223", Key: "2223", FeatureEnabled: true}
143+
var testExp1113Var2224 = entities.Variation{ID: "2224", Key: "2224", FeatureEnabled: false}
144+
var testExp1113 = entities.Experiment{
145+
ID: "1113",
146+
Key: testExp1113Key,
147+
GroupID: "6666",
148+
Variations: map[string]entities.Variation{
149+
"2223": testExp1113Var2223,
150+
"2224": testExp1113Var2224,
151+
},
152+
TrafficAllocation: []entities.Range{
153+
entities.Range{EntityID: "2223", EndOfRange: 5000},
154+
entities.Range{EntityID: "2224", EndOfRange: 10000},
155+
},
156+
}
157+
const testExp1114Key = "test_experiment_1114"
158+
var testExp1114Var2225 = entities.Variation{ID: "2225", Key: "2225", FeatureEnabled: true}
159+
var testExp1114Var2226 = entities.Variation{ID: "2226", Key: "2226", FeatureEnabled: false}
160+
var testExp1114 = entities.Experiment{
161+
ID: "1114",
162+
Key: testExp1114Key,
163+
GroupID: "6666",
164+
Variations: map[string]entities.Variation{
165+
"2225": testExp1114Var2225,
166+
"2226": testExp1114Var2226,
167+
},
168+
TrafficAllocation: []entities.Range{
169+
entities.Range{EntityID: "2225", EndOfRange: 5000},
170+
entities.Range{EntityID: "2226", EndOfRange: 10000},
171+
},
172+
}
173+
var testGroup6666 = entities.Group{
174+
ID: "6666",
175+
Policy: "random",
176+
TrafficAllocation: []entities.Range{
177+
entities.Range{EntityID: "1113", EndOfRange: 3000},
178+
entities.Range{EntityID: "1114", EndOfRange: 6000},
179+
},
180+
}
181+
182+
// Will use this experiment for rollout
183+
const testExp1115Key = "test_experiment_1115"
184+
var testExp1115Var2227 = entities.Variation{ID: "2227", Key: "2227", FeatureEnabled: true}
185+
var testExp1115 = entities.Experiment{
186+
ID: "1115",
187+
Key: testExp1115Key,
188+
Variations: map[string]entities.Variation{
189+
"2227": testExp1115Var2227,
190+
},
191+
TrafficAllocation: []entities.Range{
192+
entities.Range{EntityID: "2227", EndOfRange: 5000},
193+
},
194+
}
195+
var testFeat3335 = entities.Feature{
196+
ID: "3335",
197+
Key: testFeat3335Key,
198+
FeatureExperiments: []entities.Experiment{testExp1113, testExp1114},
199+
Rollout: entities.Rollout{
200+
ID: "4445",
201+
Experiments: []entities.Experiment{testExp1115},
202+
},
203+
}

0 commit comments

Comments
 (0)