Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDKS-7633] Add default treatment in SplitView #206

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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