Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string constraint fixes #193

Merged
merged 12 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix constraint value
  • Loading branch information
markphelps committed Nov 28, 2019
commit 4a2eff498f362c9765b7955855844b81123eba24
16 changes: 10 additions & 6 deletions rpc/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ func (req *CreateConstraintRequest) Validate() error {
return errors.ErrInvalidf("invalid constraint type: %q", req.Type.String())
}

// check if value is required
if _, ok := NoValueOperators[operator]; !ok {
return errors.EmptyFieldError("value")
if req.Value == "" {
// check if value is required
if _, ok := NoValueOperators[operator]; !ok {
return errors.EmptyFieldError("value")
}
}

return nil
Expand Down Expand Up @@ -375,9 +377,11 @@ func (req *UpdateConstraintRequest) Validate() error {
return errors.ErrInvalidf("invalid constraint type: %q", req.Type.String())
}

// check if value is required
if _, ok := NoValueOperators[operator]; !ok {
return errors.EmptyFieldError("value")
if req.Value == "" {
// check if value is required
if _, ok := NoValueOperators[operator]; !ok {
return errors.EmptyFieldError("value")
}
}

return nil
Expand Down
21 changes: 21 additions & 0 deletions rpc/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,16 @@ func TestValidate_CreateConstraintRequest(t *testing.T) {
},
wantErr: errors.ErrInvalid("invalid constraint type: \"UNKNOWN_COMPARISON_TYPE\""),
},
{
name: "ok",
req: &CreateConstraintRequest{
SegmentKey: "segmentKey",
Type: ComparisonType_STRING_COMPARISON_TYPE,
Property: "foo",
Operator: "eq",
Value: "bar",
},
},
{
name: "emptyValue ok",
req: &CreateConstraintRequest{
Expand Down Expand Up @@ -1014,6 +1024,17 @@ func TestValidate_UpdateConstraintRequest(t *testing.T) {
},
wantErr: errors.ErrInvalid("invalid constraint type: \"UNKNOWN_COMPARISON_TYPE\""),
},
{
name: "ok",
req: &UpdateConstraintRequest{
Id: "1",
SegmentKey: "segmentKey",
Type: ComparisonType_STRING_COMPARISON_TYPE,
Property: "foo",
Operator: "eq",
Value: "bar",
},
},
{
name: "emptyValue ok",
req: &UpdateConstraintRequest{
Expand Down
4 changes: 2 additions & 2 deletions script/test/api
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ step_2_test_flags_and_variants()

step_3_test_segments_and_constraints()
{
# create segment
segment_key=$(uuid_str)
segment_name_1=$(uuid_str)

# create segment
shakedown POST "$flipt_api/segments" -H 'Content-Type:application/json' -d "{\"key\":\"$segment_key\",\"name\":\"$segment_name_1\",\"description\":\"description\"}"
status 200
matches "\"key\":\"$segment_key\""
Expand All @@ -95,9 +95,9 @@ step_3_test_segments_and_constraints()
matches "\"key\":\"$segment_key\""
matches "\"name\":\"$segment_name_1\""

# update segment
segment_name_2=$(uuid_str)

# update segment
shakedown PUT "$flipt_api/segments/$segment_key" -H 'Content-Type:application/json' -d "{\"key\":\"$segment_key\",\"name\":\"$segment_name_2\",\"description\":\"description\"}"
status 200
matches "\"key\":\"$segment_key\""
Expand Down