-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra TestCheckFunc
s to check attribute's string length
#893
Extra TestCheckFunc
s to check attribute's string length
#893
Conversation
… to check resource attribute string length
This is based on the official [GitHub templates](https://github.com/github/gitignore), plus something for Jetbrains products
I'll suggest moving the .gitignore changes to a separate PR. |
helper/resource/testing.go
Outdated
@@ -1031,6 +1031,36 @@ func testCheckResourceAttrPair(isFirst *terraform.InstanceState, nameFirst strin | |||
return nil | |||
} | |||
|
|||
// TestRangeLengthResourceAttr is a TestCheckFunc which checks that the length of the value | |||
// in state for the given name/key is within an expected (closed) range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it matters in this repo, but the last linter PR I looked at wanted .
's at the end of comments.
Co-authored-by: Dave Parfitt <[email protected]>
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Background
Sometimes, when writing tests for a provider, one needs to check that a value is a certain length or length range, while cannot rely on expecting a specific value to match. This is for example true for situations when the provider will generate a value entirely randomised, but that "should be at least this long/short".
Solution proposed
2 additional functions in
helper/resource/testing.go
:func TestRangeLengthResourceAttr(name, key string, min, max int) TestCheckFunc
func TestMatchLengthResourceAttr(name, key string, length int) TestCheckFunc
This PR comes with tests to exercise this utility.