Skip to content

Commit

Permalink
Add rule path to conformance test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jchadwick-buf committed Oct 22, 2024
1 parent f624677 commit d4a7f0b
Show file tree
Hide file tree
Showing 31 changed files with 4,112 additions and 876 deletions.
28 changes: 24 additions & 4 deletions tools/protovalidate-conformance/internal/cases/cases_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@ func anySuite() suites.Suite {
"in/invalid/known": {
Message: &cases.AnyIn{Val: tsAny},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("any.in")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("any.in"),
ConstraintId: proto.String("any.in"),
},
),
},
"in/invalid/unknown": {
Message: &cases.AnyIn{Val: fooAny},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("any.in")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("any.in"),
ConstraintId: proto.String("any.in"),
},
),
},
"not_in/valid/known": {
Message: &cases.AnyNotIn{Val: durAny},
Expand All @@ -82,7 +92,12 @@ func anySuite() suites.Suite {
"not_in/invalid/known": {
Message: &cases.AnyNotIn{Val: tsAny},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("any.not_in")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("any.not_in"),
ConstraintId: proto.String("any.not_in"),
},
),
},
"required/valid/known": {
Message: &cases.AnyRequired{Val: tsAny},
Expand All @@ -95,7 +110,12 @@ func anySuite() suites.Suite {
"require/invalid": {
Message: &cases.AnyRequired{},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("required")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("required"),
ConstraintId: proto.String("required"),
},
),
},
}
}
14 changes: 12 additions & 2 deletions tools/protovalidate-conformance/internal/cases/cases_bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ func boolSuite() suites.Suite {
"const/true/invalid": {
Message: &cases.BoolConstTrue{Val: false},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bool.const")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bool.const"),
ConstraintId: proto.String("bool.const"),
},
),
},
"const/false/valid": {
Message: &cases.BoolConstFalse{Val: false},
Expand All @@ -44,7 +49,12 @@ func boolSuite() suites.Suite {
"const/false/invalid": {
Message: &cases.BoolConstFalse{Val: true},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bool.const")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bool.const"),
ConstraintId: proto.String("bool.const"),
},
),
},
"example/valid": {
Message: &cases.BoolExample{Val: true},
Expand Down
51 changes: 46 additions & 5 deletions tools/protovalidate-conformance/internal/cases/cases_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ func bytesSuite() suites.Suite {
"const/invalid": {
Message: &cases.BytesConst{Val: []byte("bar")},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bytes.const")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.const"),
ConstraintId: proto.String("bytes.const"),
},
),
},
"in/valid": {
Message: &cases.BytesIn{Val: []byte("bar")},
Expand All @@ -44,7 +49,12 @@ func bytesSuite() suites.Suite {
"in/invalid": {
Message: &cases.BytesIn{Val: []byte("quux")},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bytes.in")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.in"),
ConstraintId: proto.String("bytes.in"),
},
),
},
"not_in/valid": {
Message: &cases.BytesNotIn{Val: []byte("quux")},
Expand All @@ -53,7 +63,12 @@ func bytesSuite() suites.Suite {
"not_in/invalid": {
Message: &cases.BytesNotIn{Val: []byte("fizz")},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bytes.not_in")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.not_in"),
ConstraintId: proto.String("bytes.not_in"),
},
),
},
"len/valid": {
Message: &cases.BytesLen{Val: []byte("baz")},
Expand All @@ -62,12 +77,22 @@ func bytesSuite() suites.Suite {
"len/invalid/less": {
Message: &cases.BytesLen{Val: []byte("go")},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bytes.len")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.len"),
ConstraintId: proto.String("bytes.len"),
},
),
},
"len/invalid/greater": {
Message: &cases.BytesLen{Val: []byte("fizz")},
Expected: results.Violations(
&validate.Violation{FieldPath: proto.String("val"), ConstraintId: proto.String("bytes.len")}),
&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.len"),
ConstraintId: proto.String("bytes.len"),
},
),
},
"min_len/valid/equal": {
Message: &cases.BytesMinLen{Val: []byte("baz")},
Expand All @@ -81,6 +106,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesMinLen{Val: []byte("go")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.min_len"),
ConstraintId: proto.String("bytes.min_len"),
Message: proto.String("value length must be at least 3 bytes"),
}),
Expand All @@ -97,6 +123,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesMaxLen{Val: []byte("1234567890")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.max_len"),
ConstraintId: proto.String("bytes.max_len"),
Message: proto.String("value must be at most 5 bytes"),
}),
Expand All @@ -117,6 +144,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesMinMaxLen{Val: []byte("go")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.min_len"),
ConstraintId: proto.String("bytes.min_len"),
Message: proto.String("value length must be at least 3 bytes"),
}),
Expand All @@ -125,6 +153,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesMinMaxLen{Val: []byte("validate")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.max_len"),
ConstraintId: proto.String("bytes.max_len"),
Message: proto.String("value must be at most 5 bytes"),
}),
Expand All @@ -137,6 +166,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesEqualMinMaxLen{Val: []byte("validate")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.max_len"),
ConstraintId: proto.String("bytes.max_len"),
Message: proto.String("value must be at most 5 bytes"),
}),
Expand All @@ -149,6 +179,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesPattern{Val: []byte("你好你好")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.pattern"),
ConstraintId: proto.String("bytes.pattern"),
Message: proto.String("value must match regex pattern `^[\\x00-\\x7F]+$`"),
}),
Expand All @@ -157,6 +188,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesPattern{Val: []byte("")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.pattern"),
ConstraintId: proto.String("bytes.pattern"),
Message: proto.String("value must match regex pattern `^[\\x00-\\x7F]+$`"),
}),
Expand All @@ -177,6 +209,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesPrefix{Val: []byte("bar")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.prefix"),
ConstraintId: proto.String("bytes.prefix"),
Message: proto.String("value does not have prefix 99"),
}),
Expand All @@ -193,6 +226,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesContains{Val: []byte("candy bazs")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.contains"),
ConstraintId: proto.String("bytes.contains"),
Message: proto.String("value does not contain 626172"),
}),
Expand All @@ -209,6 +243,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesSuffix{Val: []byte("foobar")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.suffix"),
ConstraintId: proto.String("bytes.suffix"),
Message: proto.String("value does not have suffix 62757a7a"),
}),
Expand All @@ -217,6 +252,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesSuffix{Val: []byte("FooBaz")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.suffix"),
ConstraintId: proto.String("bytes.suffix"),
Message: proto.String("value does not have suffix 62757a7a"),
}),
Expand All @@ -233,6 +269,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesIP{Val: []byte("foobar")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.ip"),
ConstraintId: proto.String("bytes.ip"),
Message: proto.String("value must be a valid IP address"),
}),
Expand All @@ -249,6 +286,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesIPv4{Val: []byte("foobar")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.ipv4"),
ConstraintId: proto.String("bytes.ipv4"),
Message: proto.String("value must be a valid IPv4 address"),
}),
Expand All @@ -261,6 +299,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesIPv4{Val: []byte("\x20\x01\x0D\xB8\x85\xA3\x00\x00\x00\x00\x8A\x2E\x03\x70\x73\x34")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.ipv4"),
ConstraintId: proto.String("bytes.ipv4"),
Message: proto.String("value must be a valid IPv4 address"),
}),
Expand All @@ -273,6 +312,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesIPv6{Val: []byte("fooar")},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.ipv6"),
ConstraintId: proto.String("bytes.ipv6"),
Message: proto.String("value must be a valid IPv6 address"),
}),
Expand All @@ -285,6 +325,7 @@ func bytesSuite() suites.Suite {
Message: &cases.BytesIPv6{Val: []byte{0xC0, 0xA8, 0x00, 0x01}},
Expected: results.Violations(&validate.Violation{
FieldPath: proto.String("val"),
RulePath: proto.String("bytes.ipv6"),
ConstraintId: proto.String("bytes.ipv6"),
}),
},
Expand Down
Loading

0 comments on commit d4a7f0b

Please sign in to comment.