Skip to content

Commit

Permalink
fixup tests after changes in errors and adding trimming to raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzielenski committed Jan 25, 2024
1 parent 30aaf84 commit f4ff1f8
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions pkg/generators/markers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[2]:rule="self > 5"`,
`+k8s:validation:cel[2]:message="must be greater than 5"`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[2]:rule="self > 5": non-consecutive index 2 for key '+k8s:validation:cel'`,
expectedError: `failed to parse marker comments: error parsing cel[2]:rule="self > 5": non-consecutive index 2 for key 'cel'`,
},
{
t: types.Float64,
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[2]:optionalOldSelf=true`,
`+k8s:validation:cel[2]:message="must be greater than 5"`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[2]:rule="self > 5": non-consecutive index 2 for key '+k8s:validation:cel'`,
expectedError: `failed to parse marker comments: error parsing cel[2]:rule="self > 5": non-consecutive index 2 for key 'cel'`,
},
{
t: types.Float64,
Expand All @@ -255,7 +255,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[0]:optionalOldSelf=true`,
`+k8s:validation:cel[0]:message="must be greater than 5"`,
},
expectedError: "failed to parse marker comments: error parsing +k8s:validation:cel[0]:optionalOldSelf=true: non-consecutive index 0 for key '+k8s:validation:cel'",
expectedError: "failed to parse marker comments: error parsing cel[0]:optionalOldSelf=true: non-consecutive index 0 for key 'cel'",
},
{
t: types.Float64,
Expand All @@ -269,7 +269,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[2]:rule="a rule"`,
`+k8s:validation:cel[2]:message="message 2"`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[2]:rule="a rule": non-consecutive index 2 for key '+k8s:validation:cel'`,
expectedError: "failed to parse marker comments: error parsing cel[2]:rule=\"a rule\": non-consecutive index 2 for key 'cel'",
},
{
t: types.Float64,
Expand All @@ -283,7 +283,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[2]:rule="a rule"`,
`+k8s:validation:cel[2]:message="message 2"`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[2]:rule="a rule": non-consecutive index 2 for key '+k8s:validation:cel'`,
expectedError: "failed to parse marker comments: error parsing cel[2]:rule=\"a rule\": non-consecutive index 2 for key 'cel'",
},
{
t: types.Float64,
Expand All @@ -294,23 +294,47 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[1]:message="must be greater than 5"`,
`+k8s:validation:cel[0]:message>another raw string message`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[0]:message>another raw string message: non-consecutive index 0 for key '+k8s:validation:cel'`,
expectedError: "failed to parse marker comments: error parsing cel[0]:message>another raw string message: non-consecutive index 0 for key 'cel'",
},
{
t: types.Float64,
t: types.String,
name: "non-consecutive string indexing false positive",
comments: []string{
`+k8s:validation:cel[0]:rule> raw string rule [1]`,
`+k8s:validation:cel[0]:message>[3]string rule [1]`,
`+k8s:validation:cel[0]:rule="string rule [1]"`,
`+k8s:validation:pattern="self[3] == 'hi'"`,
},
expected: generators.CommentTags{
CEL: []generators.CELTag{
{
Rule: "string rule [1]",
Message: "[3]string rule [1]",
},
},
SchemaProps: spec.SchemaProps{
Pattern: "self[3] == 'hi'",
},
},
},
{
t: types.Float64,
t: types.String,
name: "non-consecutive raw string indexing false positive",
comments: []string{
`+k8s:validation:cel[0]:message>[3]raw string message with subscirpt [3]"`,
`+k8s:validation:cel[0]:rule> raw string rule [1]`,
`+k8s:validation:pattern>"self[3] == 'hi'"`,
},
expected: generators.CommentTags{
CEL: []generators.CELTag{
{
Rule: "raw string rule [1]",
Message: "[3]raw string message with subscirpt [3]\"",
},
},
SchemaProps: spec.SchemaProps{
Pattern: `"self[3] == 'hi'"`,
},
},
},
{
t: types.Float64,
Expand All @@ -320,7 +344,7 @@ func TestParseCommentTags(t *testing.T) {
`+k8s:validation:cel[0]:message="cant change"`,
`+k8s:validation:cel[2]:optionalOldSelf`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[2]:optionalOldSelf: non-consecutive index 2 for key '+k8s:validation:cel'`,
expectedError: `failed to parse marker comments: error parsing cel[2]:optionalOldSelf: non-consecutive index 2 for key 'cel'`,
},
{
t: types.Float64,
Expand All @@ -333,7 +357,7 @@ func TestParseCommentTags(t *testing.T) {
`+minimum=5`,
`+k8s:validation:cel[1]:optionalOldSelf`,
},
expectedError: `failed to parse marker comments: error parsing +k8s:validation:cel[1]:optionalOldSelf: non-consecutive index 1 for key '+k8s:validation:cel'`,
expectedError: `failed to parse marker comments: error parsing cel[1]:optionalOldSelf: non-consecutive index 1 for key 'cel'`,
},
{
t: types.Float64,
Expand Down Expand Up @@ -369,7 +393,7 @@ func TestParseCommentTags(t *testing.T) {
expected: generators.CommentTags{
CEL: []generators.CELTag{
{
Rule: " raw string rule",
Rule: "raw string rule",
Message: "raw string message",
},
},
Expand All @@ -387,7 +411,7 @@ func TestParseCommentTags(t *testing.T) {
expected: generators.CommentTags{
CEL: []generators.CELTag{
{
Rule: " self.length() % 2 == 0\n ? self.field == self.name + ' is even'\n : self.field == self.name + ' is odd'",
Rule: "self.length() % 2 == 0\n? self.field == self.name + ' is even'\n: self.field == self.name + ' is odd'",
Message: "raw string message",
},
},
Expand All @@ -405,7 +429,7 @@ func TestParseCommentTags(t *testing.T) {
expected: generators.CommentTags{
CEL: []generators.CELTag{
{
Rule: "self.length() % 2 == 0\n ? self.field == self.name + ' is even'\n : self.field == self.name + ' is odd'",
Rule: "self.length() % 2 == 0\n? self.field == self.name + ' is even'\n: self.field == self.name + ' is odd'",
Message: "raw string message",
},
},
Expand Down

0 comments on commit f4ff1f8

Please sign in to comment.