Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikOseberg committed Sep 27, 2023
1 parent ec6bd84 commit b80180c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type FeatureDependencies struct {
// Enabled is the property that determines whether the dependency should be on or off
// If the property is absent from the payload it's assumed to be default on
Enabled *bool `json:"enabled"`
}
}

func (fr FeatureResponse) FeatureMap() map[string]interface{} {
features := map[string]interface{}{}
Expand Down
39 changes: 19 additions & 20 deletions api/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@ import (
func TestFeatureSegmentsResponse(t *testing.T) {
assert := assert.New(t)
featureResponse := FeatureResponse{
Features: []Feature{},
Segments: []Segment{
{Id: 1, Constraints: []Constraint{
{
ContextName: "custom-id",
Operator: OperatorIn,
Values: []string{"custom-ctx"},
}}},
{Id: 2, Constraints: []Constraint{
{
ContextName: "age",
Operator: OperatorNumGte,
Value: "5",
}}},
}}
Features: []Feature{},
Segments: []Segment{
{Id: 1, Constraints: []Constraint{
{
ContextName: "custom-id",
Operator: OperatorIn,
Values: []string{"custom-ctx"},
}}},
{Id: 2, Constraints: []Constraint{
{
ContextName: "age",
Operator: OperatorNumGte,
Value: "5",
}}},
}}

segmentsMap := featureResponse.SegmentsMap();
segmentsMap := featureResponse.SegmentsMap()

segmentOne := segmentsMap[1];
segmentTwo := segmentsMap[2];
segmentOne := segmentsMap[1]
segmentTwo := segmentsMap[2]
segmentThree := segmentsMap[3]

assert.Equal(segmentOne[0].Operator, OperatorIn)
assert.Equal(segmentTwo[0].Operator, OperatorNumGte)
assert.Nil(segmentThree)
}

48 changes: 24 additions & 24 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,38 +343,38 @@ func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context cont
warnOnce := &WarnOnce{}

dependenciesSatisfied := func(parent api.FeatureDependencies) bool {
parentToggle := uc.repository.getToggle(parent.Feature)
parentToggle := uc.repository.getToggle(parent.Feature)

if parentToggle == nil {
warnOnce.Warn("the parent toggle was not found in the cache, the evaluation of this dependency will always be false")
return false
}
if parentToggle == nil {
warnOnce.Warn("the parent toggle was not found in the cache, the evaluation of this dependency will always be false")
return false
}

if parentToggle.Dependencies != nil && len(*parentToggle.Dependencies) > 0 {
return false
}
if parentToggle.Dependencies != nil && len(*parentToggle.Dependencies) > 0 {
return false
}

// According to the schema, if the enabled property is absent we assume it's true.
if parent.Enabled == nil {
if parent.Variants != nil && len(*parent.Variants) > 0 {
variantName := uc.getVariantWithoutMetrics(parent.Feature, WithVariantContext(context)).Name
return contains(*parent.Variants, variantName)
}
return uc.isEnabled(parent.Feature, WithContext(context)).Enabled
// According to the schema, if the enabled property is absent we assume it's true.
if parent.Enabled == nil {
if parent.Variants != nil && len(*parent.Variants) > 0 {
variantName := uc.getVariantWithoutMetrics(parent.Feature, WithVariantContext(context)).Name
return contains(*parent.Variants, variantName)
}

return !uc.isEnabled(parent.Feature, WithContext(context)).Enabled
return uc.isEnabled(parent.Feature, WithContext(context)).Enabled
}

allDependenciesSatisfied := every(*feature.Dependencies, func(parent interface{}) bool {
return dependenciesSatisfied(parent.(api.FeatureDependencies))
})
return !uc.isEnabled(parent.Feature, WithContext(context)).Enabled
}

if !allDependenciesSatisfied {
return false
}
allDependenciesSatisfied := every(*feature.Dependencies, func(parent interface{}) bool {
return dependenciesSatisfied(parent.(api.FeatureDependencies))
})

if !allDependenciesSatisfied {
return false
}

return true
return true

// for _, parent := range *feature.Dependencies {
// parentToggle := uc.repository.getToggle(parent.Feature)
Expand Down

0 comments on commit b80180c

Please sign in to comment.