diff --git a/go.mod b/go.mod index fdc4ecd8..ef38fe0d 100644 --- a/go.mod +++ b/go.mod @@ -59,7 +59,7 @@ require ( github.com/tinylib/msgp v1.1.0 // indirect github.com/urfave/negroni v0.3.0 github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67 - github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87 + github.com/zhouzhuojie/conditions v0.2.3 github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5 golang.org/x/net v0.0.0-20200602114024-627f9648deb9 golang.org/x/text v0.3.3 // indirect diff --git a/go.sum b/go.sum index 20af734a..756b8966 100644 --- a/go.sum +++ b/go.sum @@ -359,8 +359,8 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67 h1:BpDBAgffGUtOwUnYuFVOnl9PuDXW0X7bVw7NX/UdA4w= github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67/go.mod h1:eRmB4tpcIoEUfMNyiXTbnZtzfODhBhZB3BIWGDD+vLs= -github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87 h1:5pQTfWe/n9OvmwOamjhkePoT3dtJv0If1CXl3zkhSZg= -github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87/go.mod h1:Izhy98HD3MkfwGPz+p9ZV2JuqrpbHjaQbUq9iZHh+ZY= +github.com/zhouzhuojie/conditions v0.2.3 h1:TS3X6vA9CVXXteRdeXtpOw3hAar+01f0TI/dLp8qEvY= +github.com/zhouzhuojie/conditions v0.2.3/go.mod h1:Izhy98HD3MkfwGPz+p9ZV2JuqrpbHjaQbUq9iZHh+ZY= github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5 h1:YuR5otuPvpk6EPrKy9rVXiQKTqgY6OEqSlzko9kcfCI= github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5/go.mod h1:nhm/3zpPm56iKoXLEeeevuI5V9qEtNhuhLbPZwcrgcs= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= diff --git a/pkg/handler/crud_test.go b/pkg/handler/crud_test.go index 0c920de4..0bfc2469 100644 --- a/pkg/handler/crud_test.go +++ b/pkg/handler/crud_test.go @@ -643,7 +643,23 @@ func TestCrudConstraints(t *testing.T) { }) assert.NotZero(t, res.(*constraint.PutConstraintOK).Payload.ID) - // step 5. it should be able to delete a constraint + // step 5. it should be able to update the constraint + variousPropertyNames := []string{"test", "test-dash", "test_underscore", "@test", "@@test"} + for _, propertyName := range variousPropertyNames { + res = c.PutConstraint(constraint.PutConstraintParams{ + FlagID: int64(1), + SegmentID: int64(1), + ConstraintID: int64(1), + Body: &models.CreateConstraintRequest{ + Operator: util.StringPtr("EQ"), + Property: util.StringPtr(propertyName), + Value: util.StringPtr(`"CA"`), + }, + }) + assert.NotZero(t, res.(*constraint.PutConstraintOK).Payload.ID) + } + + // step 6. it should be able to delete a constraint res = c.DeleteConstraint(constraint.DeleteConstraintParams{ FlagID: int64(1), SegmentID: int64(1), diff --git a/pkg/handler/eval_test.go b/pkg/handler/eval_test.go index 11bb38f3..09f240c6 100644 --- a/pkg/handler/eval_test.go +++ b/pkg/handler/eval_test.go @@ -215,19 +215,31 @@ func TestEvalFlag(t *testing.T) { Operator: models.ConstraintOperatorGT, Value: `1000`, }, + { + Model: gorm.Model{ID: 503}, + SegmentID: 200, + Property: "city-name", + Operator: models.ConstraintOperatorEQ, + Value: `"SF"`, + }, } f.PrepareEvaluation() cache := &EvalCache{idCache: map[string]*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", "rate": 2000}, - EntityID: "entityID1", - EntityType: "entityType1", - FlagID: int64(100), + EnableDebug: true, + EntityContext: map[string]interface{}{ + "dl_state": "CA", + "state": "CA", + "rate": 2000, + "city-name": "SF", + }, + EntityID: "entityID1", + EntityType: "entityType1", + FlagID: int64(100), }) - assert.NotNil(t, result) - assert.NotNil(t, result.VariantID) + assert.NotZero(t, result) + assert.NotZero(t, result.VariantID) }) t.Run("test multiple segments with the first segment 0% rollout", func(t *testing.T) { diff --git a/vendor/github.com/zhouzhuojie/conditions/README.md b/vendor/github.com/zhouzhuojie/conditions/README.md index 082657ba..e5cd1c84 100644 --- a/vendor/github.com/zhouzhuojie/conditions/README.md +++ b/vendor/github.com/zhouzhuojie/conditions/README.md @@ -39,5 +39,12 @@ func main() { ``` ## Credit +Forked from [https://github.com/oleksandr/conditions](https://github.com/oleksandr/conditions) -[https://github.com/oleksandr/conditions](https://github.com/oleksandr/conditions) +The main differences are + +- Changed the syntax of variables from `[foo]` to `{foo}`. +- Added `CONTAINS`. +- Added float comparison with epsilon error torlerence. +- Optimized long array `IN`/`CONTAINS` operator. +- Removed redundant RWMutex for better performance. diff --git a/vendor/github.com/zhouzhuojie/conditions/parser.go b/vendor/github.com/zhouzhuojie/conditions/parser.go index a31f1dea..0f7c968c 100644 --- a/vendor/github.com/zhouzhuojie/conditions/parser.go +++ b/vendor/github.com/zhouzhuojie/conditions/parser.go @@ -358,6 +358,11 @@ func (p *Parser) scanArg() (rune, string, error) { continue } t, _ := p.scan() + // Allow variables to contain "-" + if t == '-' { + sep = "-" + continue + } if t == '}' { ti, _ := p.scan() if ti == '{' { diff --git a/vendor/modules.txt b/vendor/modules.txt index c19a1b9c..0d55ede3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -289,7 +289,7 @@ github.com/urfave/negroni # github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67 ## explicit github.com/yadvendar/negroni-newrelic-go-agent -# github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87 +# github.com/zhouzhuojie/conditions v0.2.3 ## explicit github.com/zhouzhuojie/conditions # github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5