Skip to content

Commit

Permalink
add celformer unit test demonstrating string regexp in CEL expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cfryanr committed Sep 13, 2023
1 parent c52ed93 commit 2cecc17
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/celtransformer/celformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ func TestTransformer(t *testing.T) {
wantUsername: "ryan",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can use regex on strings: when the regex matches",
username: "ryan",
groups: []string{"admins", "developers", "other"},
transforms: []CELTransformation{
&UsernameTransformation{Expression: `username.matches("^r[abcy].n$") ? "ryan-modified" : username`},
},
wantUsername: "ryan-modified",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can use regex on strings: when the regex does not match",
username: "olive",
groups: []string{"admins", "developers", "other"},
transforms: []CELTransformation{
&UsernameTransformation{Expression: `username.matches("^r[abcy].n$") ? "ryan-modified" : username`},
},
wantUsername: "olive",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can filter groups based on an allow list",
username: "ryan",
Expand Down

0 comments on commit 2cecc17

Please sign in to comment.