diff --git a/pkg/client/fixtures_test.go b/pkg/client/fixtures_test.go index 13816697..a8ecac52 100644 --- a/pkg/client/fixtures_test.go +++ b/pkg/client/fixtures_test.go @@ -86,6 +86,14 @@ func (c *MockProjectConfig) GetRegion() string { return "US" } +func (c *MockProjectConfig) GetHoldoutList() []entities.Holdout { + return []entities.Holdout{} +} + +func (c *MockProjectConfig) GetHoldoutsForFlag(featureKey string) []entities.Holdout { + return []entities.Holdout{} +} + type MockProjectConfigManager struct { projectConfig config.ProjectConfig mock.Mock diff --git a/pkg/cmab/service_test.go b/pkg/cmab/service_test.go index 4675d773..71a9a235 100644 --- a/pkg/cmab/service_test.go +++ b/pkg/cmab/service_test.go @@ -235,6 +235,11 @@ func (m *MockProjectConfig) GetHoldoutsForFlag(featureKey string) []entities.Hol return args.Get(0).([]entities.Holdout) } +func (m *MockProjectConfig) GetHoldoutList() []entities.Holdout { + args := m.Called() + return args.Get(0).([]entities.Holdout) +} + type CmabServiceTestSuite struct { suite.Suite mockClient *MockCmabClient diff --git a/pkg/config/datafileprojectconfig/config.go b/pkg/config/datafileprojectconfig/config.go index 13526875..cb1bd8ec 100644 --- a/pkg/config/datafileprojectconfig/config.go +++ b/pkg/config/datafileprojectconfig/config.go @@ -292,6 +292,11 @@ func (c DatafileProjectConfig) GetHoldoutsForFlag(featureKey string) []entities. return []entities.Holdout{} } +// GetHoldoutList returns all holdouts in the project +func (c DatafileProjectConfig) GetHoldoutList() []entities.Holdout { + return c.holdouts +} + // NewDatafileProjectConfig initializes a new datafile from a json byte array using the default JSON datafile parser func NewDatafileProjectConfig(jsonDatafile []byte, logger logging.OptimizelyLogProducer) (*DatafileProjectConfig, error) { datafile, err := Parse(jsonDatafile) diff --git a/pkg/config/interface.go b/pkg/config/interface.go index 6d45c14a..3c58e143 100644 --- a/pkg/config/interface.go +++ b/pkg/config/interface.go @@ -57,6 +57,7 @@ type ProjectConfig interface { GetFlagVariationsMap() map[string][]entities.Variation GetRegion() string GetHoldoutsForFlag(featureKey string) []entities.Holdout + GetHoldoutList() []entities.Holdout } // ProjectConfigManager maintains an instance of the ProjectConfig diff --git a/pkg/config/testdata/holdouts_datafile.json b/pkg/config/testdata/holdouts_datafile.json new file mode 100644 index 00000000..30bd5380 --- /dev/null +++ b/pkg/config/testdata/holdouts_datafile.json @@ -0,0 +1,241 @@ +{ + "accountId": "12133785640", + "projectId": "6460519658291200", + "revision": "12", + "attributes": [ + { + "id": "5502380200951808", + "key": "all" + }, + { + "id": "5750214343000064", + "key": "ho" + } + ], + "audiences": [ + { + "name": "ho_3_aud", + "conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]", + "id": "5435551013142528" + }, + { + "name": "ho_6_aud", + "conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]", + "id": "5841838209236992" + }, + { + "name": "ho_4_aud", + "conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]", + "id": "6043616745881600" + }, + { + "name": "ho_5_aud", + "conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]", + "id": "6410995866796032" + }, + { + "id": "$opt_dummy_audience", + "name": "Optimizely-Generated Audience for Backwards Compatibility", + "conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]" + } + ], + "version": "4", + "events": [ + { + "id": "6554438379241472", + "experimentIds": [], + "key": "event1" + } + ], + "integrations": [], + "holdouts": [ + { + "id": "1673115", + "key": "holdout_6", + "status": "Running", + "variations": [ + { + "id": "$opt_dummy_variation_id", + "key": "off", + "featureEnabled": false, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "$opt_dummy_variation_id", + "endOfRange": 4000 + } + ], + "audienceIds": ["5841838209236992"], + "audienceConditions": ["or", "5841838209236992"] + }, + { + "id": "1673114", + "key": "holdout_5", + "status": "Running", + "variations": [ + { + "id": "$opt_dummy_variation_id", + "key": "off", + "featureEnabled": false, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "$opt_dummy_variation_id", + "endOfRange": 2000 + } + ], + "audienceIds": ["6410995866796032"], + "audienceConditions": ["or", "6410995866796032"] + }, + { + "id": "1673113", + "key": "holdouts_4", + "status": "Running", + "variations": [ + { + "id": "$opt_dummy_variation_id", + "key": "off", + "featureEnabled": false, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "$opt_dummy_variation_id", + "endOfRange": 5000 + } + ], + "audienceIds": ["6043616745881600"], + "audienceConditions": ["or", "6043616745881600"] + }, + { + "id": "1673112", + "key": "holdout_3", + "status": "Running", + "variations": [ + { + "id": "$opt_dummy_variation_id", + "key": "off", + "featureEnabled": false, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "$opt_dummy_variation_id", + "endOfRange": 1000 + } + ], + "audienceIds": ["5435551013142528"], + "audienceConditions": ["or", "5435551013142528"] + } + ], + "anonymizeIP": true, + "botFiltering": false, + "typedAudiences": [ + { + "name": "ho_3_aud", + "conditions": ["and", ["or", ["or", {"match": "exact", "name": "ho", "type": "custom_attribute", "value": 3}]], ["or", {"match": "le", "name": "all", "type": "custom_attribute", "value": 3}]], + "id": "5435551013142528" + }, + { + "name": "ho_6_aud", + "conditions": ["and", ["or", ["or", {"match": "exact", "name": "ho", "type": "custom_attribute", "value": 6}]], ["or", {"match": "le", "name": "all", "type": "custom_attribute", "value": 6}]], + "id": "5841838209236992" + }, + { + "name": "ho_4_aud", + "conditions": ["and", ["or", ["or", {"match": "exact", "name": "ho", "type": "custom_attribute", "value": 4}]], ["or", {"match": "le", "name": "all", "type": "custom_attribute", "value": 4}]], + "id": "6043616745881600" + }, + { + "name": "ho_5_aud", + "conditions": ["and", ["or", ["or", {"match": "exact", "name": "ho", "type": "custom_attribute", "value": 5}]], ["or", {"match": "le", "name": "all", "type": "custom_attribute", "value": 5}]], + "id": "6410995866796032" + } + ], + "variables": [], + "environmentKey": "production", + "sdkKey": "BLsSFScP7tSY5SCYuKn8c", + "featureFlags": [ + { + "id": "497759", + "key": "flag1", + "rolloutId": "rollout-497759-631765411405174", + "experimentIds": [], + "variables": [] + }, + { + "id": "497760", + "key": "flag2", + "rolloutId": "rollout-497760-631765411405174", + "experimentIds": [], + "variables": [] + } + ], + "rollouts": [ + { + "id": "rollout-497759-631765411405174", + "experiments": [ + { + "id": "default-rollout-497759-631765411405174", + "key": "default-rollout-497759-631765411405174", + "status": "Running", + "layerId": "rollout-497759-631765411405174", + "variations": [ + { + "id": "1583341", + "key": "variation_1", + "featureEnabled": true, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "1583341", + "endOfRange": 10000 + } + ], + "forcedVariations": {}, + "audienceIds": [], + "audienceConditions": [] + } + ] + }, + { + "id": "rollout-497760-631765411405174", + "experiments": [ + { + "id": "default-rollout-497760-631765411405174", + "key": "default-rollout-497760-631765411405174", + "status": "Running", + "layerId": "rollout-497760-631765411405174", + "variations": [ + { + "id": "1583340", + "key": "variation_2", + "featureEnabled": true, + "variables": [] + } + ], + "trafficAllocation": [ + { + "entityId": "1583340", + "endOfRange": 10000 + } + ], + "forcedVariations": {}, + "audienceIds": [], + "audienceConditions": [] + } + ] + } + ], + "experiments": [], + "groups": [], + "region": "US" +} diff --git a/pkg/decision/evaluator/audience_evaluator_test.go b/pkg/decision/evaluator/audience_evaluator_test.go index 75897aed..1eb6dadf 100644 --- a/pkg/decision/evaluator/audience_evaluator_test.go +++ b/pkg/decision/evaluator/audience_evaluator_test.go @@ -205,6 +205,11 @@ func (m *MockProjectConfig) GetHoldoutsForFlag(featureKey string) []entities.Hol return args.Get(0).([]entities.Holdout) } +func (m *MockProjectConfig) GetHoldoutList() []entities.Holdout { + args := m.Called() + return args.Get(0).([]entities.Holdout) +} + // MockLogger is a mock implementation of OptimizelyLogProducer // (This declaration has been removed to resolve the redeclaration error)