Skip to content

Commit b81d18e

Browse files
committed
Add prerequisites in split dto
1 parent 1a8d4e3 commit b81d18e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

dtos/split.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ type SplitDTO struct {
3838
Configurations map[string]string `json:"configurations"`
3939
Sets []string `json:"sets"`
4040
ImpressionsDisabled bool `json:"impressionsDisabled"`
41+
Prerequisites []Prerequisite `json:"prerequisites"`
4142
}
4243

4344
// MarshalBinary exports SplitDTO to JSON string
4445
func (s SplitDTO) MarshalBinary() (data []byte, err error) {
4546
return json.Marshal(s)
4647
}
4748

49+
// Prerequisites structure to map a Prerequisite fetched from JSON message
50+
type Prerequisite struct {
51+
FeatureFlagName string `json:"n"`
52+
Treatments []string `json:"ts"`
53+
}
54+
4855
// ConditionDTO structure to map a Condition fetched from JSON message.
4956
type ConditionDTO struct {
5057
ConditionType string `json:"conditionType"`

dtos/split_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ func TestSplitDTO(t *testing.T) {
5050
t.Error("Marshal struct mal formed [Configurations]")
5151
}
5252

53+
if splitChangesDtoFromMarshal.FeatureFlags.Splits[0].Prerequisites == nil {
54+
t.Error("Marshal struct mal formed [Prerequisites]")
55+
}
56+
57+
if splitChangesDtoFromMarshal.FeatureFlags.Splits[0].Prerequisites[0].FeatureFlagName != "rbs_test_flag" {
58+
t.Error("Marshal struct mal formed [Prerequisites]")
59+
}
60+
61+
if splitChangesDtoFromMarshal.FeatureFlags.Splits[0].Prerequisites[0].Treatments[0] != "v1" {
62+
t.Error("Marshal struct mal formed [Prerequisites]")
63+
}
64+
5365
if splitChangesDtoFromMarshal.FeatureFlags.Splits[0].Configurations["of"] !=
5466
splitChangesDtoFromMock.FeatureFlags.Splits[0].Configurations["of"] {
5567
t.Error("Marshal struct mal formed [Configurations]")

testdata/split_mock.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
"configurations": {
1313
"on": "{\"color\": \"blue\",\"size\": 13}"
1414
},
15+
"prerequisites": [
16+
{
17+
"n": "rbs_test_flag",
18+
"ts": [
19+
"v1"
20+
]
21+
}
22+
],
1523
"conditions": [
1624
{
1725
"conditionType": "WHITELIST",

0 commit comments

Comments
 (0)