From e8e314e9e6d4c8e51e11882456eab2bda7ecd164 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 21 Nov 2023 11:48:46 -0300 Subject: [PATCH] [SDKS-7633] Add default treatment in SplitView --- splitio/client/manager.go | 30 ++++++++++++++++-------------- splitio/client/manager_test.go | 24 +++++++++++++++++++----- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/splitio/client/manager.go b/splitio/client/manager.go index c9cb71c..756340b 100644 --- a/splitio/client/manager.go +++ b/splitio/client/manager.go @@ -19,13 +19,14 @@ type SplitManager struct { // SplitView is a partial representation of a currently stored split type SplitView struct { - Name string `json:"name"` - TrafficType string `json:"trafficType"` - Killed bool `json:"killed"` - Treatments []string `json:"treatments"` - ChangeNumber int64 `json:"changeNumber"` - Configs map[string]string `json:"configs"` - Sets []string `json:"sets"` + Name string `json:"name"` + TrafficType string `json:"trafficType"` + Killed bool `json:"killed"` + Treatments []string `json:"treatments"` + ChangeNumber int64 `json:"changeNumber"` + Configs map[string]string `json:"configs"` + DefaultTreatment string `json:"defaultTreatment"` + Sets []string `json:"sets"` } func newSplitView(splitDto *dtos.SplitDTO) *SplitView { @@ -40,13 +41,14 @@ func newSplitView(splitDto *dtos.SplitDTO) *SplitView { sets = splitDto.Sets } return &SplitView{ - ChangeNumber: splitDto.ChangeNumber, - Killed: splitDto.Killed, - Name: splitDto.Name, - TrafficType: splitDto.TrafficTypeName, - Treatments: treatments, - Configs: splitDto.Configurations, - Sets: sets, + ChangeNumber: splitDto.ChangeNumber, + Killed: splitDto.Killed, + Name: splitDto.Name, + TrafficType: splitDto.TrafficTypeName, + Treatments: treatments, + Configs: splitDto.Configurations, + DefaultTreatment: splitDto.DefaultTreatment, + Sets: sets, } } diff --git a/splitio/client/manager_test.go b/splitio/client/manager_test.go index 9f7d85d..9708101 100644 --- a/splitio/client/manager_test.go +++ b/splitio/client/manager_test.go @@ -15,11 +15,12 @@ func TestSplitManager(t *testing.T) { splitStorage := mutexmap.NewMMSplitStorage(flagSetFilter) splitStorage.Update([]dtos.SplitDTO{ { - ChangeNumber: 123, - Name: "split1", - Killed: false, - TrafficTypeName: "tt1", - Sets: []string{"set1", "set2"}, + ChangeNumber: 123, + Name: "split1", + Killed: false, + TrafficTypeName: "tt1", + Sets: []string{"set1", "set2"}, + DefaultTreatment: "s1p1", Conditions: []dtos.ConditionDTO{ { Partitions: []dtos.PartitionDTO{ @@ -76,6 +77,10 @@ func TestSplitManager(t *testing.T) { t.Error("split1 should have 2 sets") } + if s1.DefaultTreatment != "s1p1" { + t.Error("the default treatment for split1 should be s1p1") + } + s2 := manager.Split("split2") if s2.Name != "split2" || !s2.Killed || s2.TrafficType != "tt2" || s2.ChangeNumber != 123 { t.Error("Split 2 stored incorrectly") @@ -135,6 +140,9 @@ func TestSplitManagerWithConfigs(t *testing.T) { if s1.Configs["on"] != "{\"color\": \"blue\",\"size\": 13}" { t.Error("It should have configs") } + if s1.DefaultTreatment != "off" { + t.Error("the default treatment for valid should be off") + } s2 := manager.Split("killed") if s2.Name != "killed" || !s2.Killed || s2.TrafficType != "user" || s2.ChangeNumber != 1494593336752 { @@ -149,6 +157,9 @@ func TestSplitManagerWithConfigs(t *testing.T) { if s2.Configs["defTreatment"] != "{\"color\": \"orange\",\"size\": 15}" { t.Error("It should have configs") } + if s2.DefaultTreatment != "defTreatment" { + t.Error("the default treatment for killed should be defTreatment") + } s3 := manager.Split("noConfig") if s3.Name != "noConfig" || s3.Killed || s3.TrafficType != "user" || s3.ChangeNumber != 1494593336752 { @@ -160,6 +171,9 @@ func TestSplitManagerWithConfigs(t *testing.T) { if s3.Configs != nil { t.Error("It should not have configs") } + if s3.DefaultTreatment != "defTreatment" { + t.Error("the default treatment for killed should be defTreatment") + } all := manager.Splits() if len(all) != 3 {