Skip to content

Commit

Permalink
Update conditions to include dash constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzhuojie committed Aug 21, 2020
1 parent 9c5e30c commit 6c340e8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 17 additions & 1 deletion pkg/handler/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
26 changes: 19 additions & 7 deletions pkg/handler/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion vendor/github.com/zhouzhuojie/conditions/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/zhouzhuojie/conditions/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c340e8

Please sign in to comment.