hashicorp / sentinel-sdk

This SDK allows developers to extend Sentinel to source external information for use in their policies.
Mozilla Public License 2.0
51 stars 13 forks source link

Add regular expression support to TestImportCase.Error #41

Closed chrisarcand closed 4 years ago

chrisarcand commented 4 years ago

This allows an Error string to contain a regular expression to be compiled and matched against the error output. If the Error string is delimited by slashes, it's used as a regular expression. Otherwise, the normal behavior (substring to be contained in the error output) is preserved.

Examples:

// Direct helper API
TestImportCase{Error: `normal substring`}
TestImportCase{Error: "normal substring"}
TestImportCase{Error: `/a \w+ pattern/`}
TestImportCase{Error: "/a \\w+ pattern/"}
# In a test file, the error pragma:
//error normal substring
//error /a \w+ pattern/

Errors in the given error pattern are helpfully surfaced, though this I found to be basically impossible to test because I don't know how to get the output to match on. (It's still tested, but like a similar other test in the suite, it just ensures that some sort of failure occurred) It looks like this:

image