Skip to content

Commit

Permalink
Make conformance and rule messages more consistent (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfus authored Jun 9, 2023
1 parent 673fbf1 commit 94061fd
Show file tree
Hide file tree
Showing 13 changed files with 993 additions and 990 deletions.
20 changes: 10 additions & 10 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2434,13 +2434,13 @@ message StringRules {
//
//```proto
//message MyString {
// // value must equal 5 runes
// // value length must be 5 characters
// string value = 1 [(buf.validate.field).string.len = 5];
//}
//```
optional uint64 len = 19 [(priv.field).cel = {
id: "string.len",
expression: "uint(this.size()) != rules.len ? 'value must equal %s runes'.format([rules.len]) : ''"
expression: "uint(this.size()) != rules.len ? 'value length must be %s characters'.format([rules.len]) : ''"
}];

//`min_len` specifies that the field value must have at least the specified
Expand All @@ -2450,13 +2450,13 @@ message StringRules {
//
//```proto
//message MyString {
// // value length must be at least 3 runes
// // value length must be at least 3 characters
// string value = 1 [(buf.validate.field).string.min_len = 3];
//}
//```
optional uint64 min_len = 2 [(priv.field).cel = {
id: "string.min_len",
expression: "uint(this.size()) < rules.min_len ? 'value length must be at least %s runes'.format([rules.min_len]) : ''"
expression: "uint(this.size()) < rules.min_len ? 'value length must be at least %s characters'.format([rules.min_len]) : ''"
}];

//`max_len` specifies that the field value must have no more than the specified
Expand All @@ -2466,13 +2466,13 @@ message StringRules {
//
//```proto
//message MyString {
// // value length must be at most 10 runes
// // value length must be at most 10 characters
// string value = 1 [(buf.validate.field).string.max_len = 10];
//}
//```
optional uint64 max_len = 3 [(priv.field).cel = {
id: "string.max_len",
expression: "uint(this.size()) > rules.max_len ? 'value length must be at most %s runes'.format([rules.max_len]) : ''"
expression: "uint(this.size()) > rules.max_len ? 'value length must be at most %s characters'.format([rules.max_len]) : ''"
}];

//`len_bytes` dictates that the field value must have the specified number of
Expand Down Expand Up @@ -2878,13 +2878,13 @@ message BytesRules {
//
//```proto
//message MyBytes {
// // value must be at least 2 bytes.
// // value length must be at least 2 bytes.
// optional bytes value = 1 [(buf.validate.field).bytes.min_len = 2];
//}
//```
optional uint64 min_len = 2 [(priv.field).cel = {
id: "bytes.min_len",
expression: "uint(this.size()) < rules.min_len ? 'value must be at least %s bytes'.format([rules.min_len]) : ''"
expression: "uint(this.size()) < rules.min_len ? 'value length must be at least %s bytes'.format([rules.min_len]) : ''"
}];

//`max_len` requires the field value to have at most the specified maximum
Expand All @@ -2910,13 +2910,13 @@ message BytesRules {
//
//```proto
//message MyBytes {
// // value must match pattern "^[a-zA-Z0-9]+$".
// // value must match regex pattern "^[a-zA-Z0-9]+$".
// optional bytes value = 1 [(buf.validate.field).bytes.pattern = "^[a-zA-Z0-9]+$"];
//}
//```
optional string pattern = 4 [(priv.field).cel = {
id: "bytes.pattern",
expression: "!string(this).matches(rules.pattern) ? 'value must match pattern %s'.format([rules.pattern]) : ''"
expression: "!string(this).matches(rules.pattern) ? 'value must match regex pattern `%s`'.format([rules.pattern]) : ''"
}];

//`prefix` requires the field value to have the specified bytes at the
Expand Down
1,660 changes: 831 additions & 829 deletions tools/internal/gen/buf/validate/validate.pb.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions tools/protovalidate-conformance/internal/cases/cases_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.min_len",
Message: "value must be at least 3 bytes long",
Message: "value length must be at least 3 bytes",
}),
},
"max_len/valid": {
Expand All @@ -97,7 +97,7 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.max_len",
Message: "value must be at most 5 bytes long",
Message: "value must be at most 5 bytes",
}),
},
"min/max_len/valid-01": {
Expand All @@ -117,7 +117,7 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.min_len",
Message: "value must be at least 3 bytes long",
Message: "value length must be at least 3 bytes",
}),
},
"min/max_len/invalid/above": {
Expand Down Expand Up @@ -149,15 +149,15 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.pattern",
Message: "value must match the pattern \"你好你好\"",
Message: "value must match regex pattern `^[-]+$`",
}),
},
"pattern/invalid/empty": {
Message: &cases.BytesPattern{Val: []byte("")},
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.pattern",
Message: "value must match the pattern \"\"",
Message: "value must match regex pattern `^[-]+$`",
}),
},
"pattern/invalid/not_utf8": {
Expand All @@ -177,7 +177,7 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.prefix",
Message: "value must have the prefix \"foo\"",
Message: "value does not have prefix 99",
}),
},
"contains/valid": {
Expand All @@ -193,7 +193,7 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.contains",
Message: "value must contain \"bar\"",
Message: "value does not contain 626172",
}),
},
"suffix/valid": {
Expand All @@ -209,15 +209,15 @@ func bytesSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.suffix",
Message: "value must have the suffix \"baz\"",
Message: "value does not have suffix 62757a7a",
}),
},
"suffix/case_sensitive/invalid": {
Message: &cases.BytesSuffix{Val: []byte("FooBaz")},
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "bytes.suffix",
Message: "value must have the suffix \"baz\"",
Message: "value does not have suffix 62757a7a",
}),
},
"IP/valid/v4": {
Expand Down
36 changes: 18 additions & 18 deletions tools/protovalidate-conformance/internal/cases/cases_duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.const",
Message: "field must be exactly the specified value",
Message: "value must equal 3s",
}),
},
"in/valid": {
Expand All @@ -89,7 +89,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.in",
Message: "field must be in the specified set of values",
Message: `value must be in list [duration("1s"), duration("0.000001s")]`,
}),
},
"not in/valid": {
Expand All @@ -110,7 +110,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.not_in",
Message: "field must not be in the specified set of values",
Message: `value must not be in list [duration("0s")]`,
}),
},
"lt/valid": {
Expand All @@ -131,7 +131,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.lt",
Message: "field must be less than 0s",
Message: "value must be less than 0s",
}),
},
"lt/invalid": {
Expand All @@ -143,7 +143,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.lt",
Message: "field must be less than 0s",
Message: "value must be less than 0s",
}),
},
"lte/valid": {
Expand Down Expand Up @@ -205,7 +205,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt",
Message: "must be greater than 0.000001s",
Message: "value must be greater than 0.000001s",
}),
},
"gte/valid": {
Expand Down Expand Up @@ -234,7 +234,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gte",
Message: "must be greater than or equal to 0.001s",
Message: "value must be greater than or equal to 0.001s",
}),
},
"gt_lt/valid": {
Expand All @@ -257,7 +257,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt",
Message: "must be greater than 0s and less than 1s",
Message: "value must be greater than 0s and less than 1s",
}),
},
"gt_lt/invalid/below": {
Expand All @@ -268,7 +268,7 @@ func durationSuite() suites.Suite {
}, Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt",
Message: "must be greater than 0s and less than 1s",
Message: "value must be greater than 0s and less than 1s",
}),
},
"gt_lt/invalid/max": {
Expand All @@ -280,7 +280,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt",
Message: "must be greater than 0s and less than 1s",
Message: "value must be greater than 0s and less than 1s",
}),
},
"gt_lt/invalid/min": {
Expand All @@ -290,7 +290,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt",
Message: "must be greater than 0s and less than 1s",
Message: "value must be greater than 0s and less than 1s",
}),
},
"gt_lt/exclusive/valid/empty": {
Expand Down Expand Up @@ -321,7 +321,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt_exclusive",
Message: "must be greater than 1s or less than 0s",
Message: "value must be greater than 1s or less than 0s",
}),
},
"gt_lt/exclusive/invalid/max": {
Expand All @@ -333,7 +333,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt_exclusive",
Message: "must be greater than 1s or less than 0s",
Message: "value must be greater than 1s or less than 0s",
}),
},
"gt_lt/exclusive/invalid/min": {
Expand All @@ -343,7 +343,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gt_lt_exclusive",
Message: "must be greater than 1s or less than 0s",
Message: "value must be greater than 1s or less than 0s",
}),
},
"gte_lte/valid": {
Expand Down Expand Up @@ -379,7 +379,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gte_lte",
Message: "must be greater than or equal to 60s and less than or equal to 3600s",
Message: "value must be greater than or equal to 60s and less than or equal to 3600s",
}),
},
"gte_lte/invalid/below": {
Expand All @@ -391,7 +391,7 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gte_lte",
Message: "must be greater than or equal to 60s and less than or equal to 3600s",
Message: "value must be greater than or equal to 60s and less than or equal to 3600s",
}),
},
"Ex gte_lte/valid/empty": {
Expand Down Expand Up @@ -434,15 +434,15 @@ func durationSuite() suites.Suite {
Expected: results.Violations(&validate.Violation{
FieldPath: "val",
ConstraintId: "duration.gte_lte_exclusive",
Message: "must be greater than or equal to 3600s or less than or equal to 60s",
Message: "value must be greater than or equal to 3600s or less than or equal to 60s",
}),
},
"fields_with_other_fields/invalid_other_field": {
Message: &cases.DurationFieldWithOtherFields{DurationVal: nil, IntVal: 12},
Expected: results.Violations(&validate.Violation{
FieldPath: "int_val",
ConstraintId: "int32.gt",
Message: "must be greater than 16",
Message: "value must be greater than 16",
}),
},
}
Expand Down
Loading

0 comments on commit 94061fd

Please sign in to comment.