diff --git a/pkg/entity/constraint.go b/pkg/entity/constraint.go index 64c6f725..a9db2b48 100644 --- a/pkg/entity/constraint.go +++ b/pkg/entity/constraint.go @@ -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 diff --git a/pkg/handler/eval_test.go b/pkg/handler/eval_test.go index 53e96109..b51e169c 100644 --- a/pkg/handler/eval_test.go +++ b/pkg/handler/eval_test.go @@ -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)),