Skip to content

Commit

Permalink
Merge pull request #206 from splitio/SDKS-7633
Browse files Browse the repository at this point in the history
[SDKS-7633] Add default treatment in SplitView
  • Loading branch information
nmayorsplit authored Nov 21, 2023
2 parents 590666f + e8e314e commit 034bc58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
30 changes: 16 additions & 14 deletions splitio/client/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand Down
24 changes: 19 additions & 5 deletions splitio/client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 034bc58

Please sign in to comment.