Skip to content

Commit

Permalink
Merge pull request #104 from checkr/zz/fix-composition-constraints
Browse files Browse the repository at this point in the history
Fix constraints composition bug
  • Loading branch information
zhouzhuojie authored Mar 19, 2018
2 parents 34b59e6 + b2c2c47 commit 1e7ea8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/entity/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *Constraint) toExprStr() (string, error) {
return "", fmt.Errorf("not supported operator: %s", c.Operator)
}

return fmt.Sprintf("{%s} %s %s", c.Property, o, c.Value), nil
return fmt.Sprintf("({%s} %s %s)", c.Property, o, c.Value), nil
}

// Validate validates Constraint
Expand Down
11 changes: 9 additions & 2 deletions pkg/handler/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,26 @@ func TestEvalFlag(t *testing.T) {
Value: `"CA"`,
},
{
Model: gorm.Model{ID: 500},
Model: gorm.Model{ID: 501},
SegmentID: 200,
Property: "state",
Operator: models.ConstraintOperatorEQ,
Value: `{dl_state}`,
},
{
Model: gorm.Model{ID: 502},
SegmentID: 200,
Property: "rate",
Operator: models.ConstraintOperatorGT,
Value: `1000`,
},
}
f.PrepareEvaluation()
cache := &EvalCache{mapCache: map[uint]*entity.Flag{100: &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA", "state": "CA"},
EntityContext: map[string]interface{}{"dl_state": "CA", "state": "CA", "rate": 2000},
EntityID: util.StringPtr("entityID1"),
EntityType: util.StringPtr("entityType1"),
FlagID: util.Int64Ptr(int64(100)),
Expand Down

0 comments on commit 1e7ea8c

Please sign in to comment.