-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[PROPOSAL] Implement TypeSet resource.TestCheckFuncs #13556
Conversation
This looks great, @appilon! How does it handle collections nested inside a
I searched for |
Definitely looking forward to this as I have to tweak another set of acceptance test values 😄. |
Thanks @gdavison
😂 I'm not sure how to handle this yet, was deliberately NOT looking for those cases, but I'll focus on this now. |
@gdavison @ewbankkit The implementation has changed to support nesting sets. |
Is there a way to check the case of a I'd like to be able to differentiate the list items, and I'm not sure how I'd do that using the resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.2000431762.date", ""),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.2000431762.days", "30"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.2000431762.storage_class", "STANDARD_IA"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3601168188.date", ""),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3601168188.days", "60"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3601168188.storage_class", "INTELLIGENT_TIERING"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3854926587.date", ""),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3854926587.days", "90"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.3854926587.storage_class", "ONEZONE_IA"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.962205413.date", ""),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.962205413.days", "120"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.962205413.storage_class", "GLACIER"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.1571523406.date", ""),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.1571523406.days", "210"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.0.transition.1571523406.storage_class", "DEEP_ARCHIVE"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.2.transition.460947558.days", "0"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.4.transition.460947558.days", "0"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.4.transition.460947558.storage_class", "GLACIER"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.5.transition.460947558.days", "0"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_rule.5.transition.460947558.storage_class", "GLACIER"), |
@gdavison Indeed it appears this implementation wouldn't be able to discern between those list items since the depth is the same 😢 . These are great examples though keep them coming, back to the drawing board! |
@ewbankkit @gdavison oookay hopefully this covers all cases. |
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.
Looks great! One question, because it looks like a test is changing
resource.TestCheckNoResourceAttr(resourceName, "parameter.2475805061.value"), | ||
resource.TestCheckNoResourceAttr(resourceName, "parameter.1706463059.value"), | ||
resource.TestCheckResourceAttr(resourceName, "parameter.#", "3"), | ||
test.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{ | ||
"name": "character_set_results", | ||
"value": "utf8", | ||
}), | ||
test.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{ | ||
"name": "character_set_server", | ||
"value": "utf8", | ||
}), | ||
test.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{ | ||
"name": "character_set_client", | ||
"value": "utf8", | ||
}), |
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.
This seems to be changing the test, since there were two items, and no values set for value
, and now there are three and they have values.. Is that intentional?
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.
Ah yes this is a bit quirky. There isn't really anyway to represent a specific set element that doesn't exist... My PR proposes helpers to guarantee a single element meets the desired criteria. So I flipped the test to "3 elements with the following property maps, and that the set only contains 3 entries (and not 5)"
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 inferred that this is what was being validated by looking at the test config (goes from 5 parameters to 3)
Okay although flaky the last example you mentioned @gdavison has passed 🎉
|
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.
This should cover us for now! Two notes below, otherwise looks good to me. 🚀
aws/internal/test/testing.go
Outdated
@@ -0,0 +1,114 @@ | |||
package test |
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.
It would be super awesome if these new testing functions had unit testing so they can be updated without needing to verify with various acceptance tests. 👍 I'm also not the biggest fan of the package being named test
since the function names already relay that (I'd suggest tfawsresource
), but that's a personal nit since its internal to this module until it is migrated to the SDK.
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.
no problem I can change the package name
aws/internal/test/testing.go
Outdated
) | ||
|
||
const ( | ||
sentinelIndex = "*" |
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.
Is it worth having the functions return an error if this sentinel value is not present or present more than once?
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 can return error if the last part in the address isn't *
, since it always should
Added check that the last part of a path is in fact the sentinel value
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
This proposed PR would add 2 helper
resource.TestCheckFunc
that can substitute current checks that use a pre-calculated hash in thekey
. These functions essentially search all of the instance state for aschema.TypeSet
element that matches either the simple value or a nested group of attr/value pairs.In V2 of the SDK, the underlying test driver uses this library which naively exports TypeSets as a list so this implementation supports both "element ids" of either number or hash.
TypeSet indexes should be substituted with the sentinel value
*
, this works across deep nesting.TestCheckTypeSetElemNestedAttrs
should be used with a granular value map to ensure an element is a full match.Examples
Deep TypeSet simple element
TypeSet nested object
TypeSet with downstream TypeList
TypeSet with downstream TypeList with downstream TypeSet