Skip to content
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

Add additional function for parsing traversals with [*] keys #673

Merged
merged 2 commits into from Apr 22, 2024

Conversation

liamcervante
Copy link
Member

This PR will eventually be used within Terraform to parse the "partial" addresses used by the deferred actions. We need support for the wildcards within traversals in order to reuse the larger logic for parsing traversals in general.

I've created a separate function for this so that this is a non-breaking change. For now, I haven't updated the behaviour of SplatTraversal so the automatic traversal functions will panic if called on a Traversal that contains the [*] index. We don't need this behaviour in Terraform (yet?) so I didn't want to introduce anything that couldn't be changed later.

Copy link
Collaborator

@DanielMSchmidt DanielMSchmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks got to me from my limited understanding

}

for _, test := range tests {
t.Run(test.src, func(t *testing.T) {
if test.src == "foo[*]" {
// Skip the test that introduces splat syntax.
t.Skip("skipping test for unsupported splat syntax")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand this right that we skip it here since we use ParseTraversalAbs in which case this is unsupported, but include it in the partial_ test cases since ParseTraversalPartial supports it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly. Basically, I wanted to make sure that using the splat was still broken in the old implementation but worked in the new one. I figured the easiest way to do that was to just manually skip the relevant tests since there's only one of each branch that needs to be skipped.

I could complicate the whole function by adding in some additional metadata to the test cases, but thought it was overkill just for one case.

t.Run(fmt.Sprintf("partial_%s", test.src), func(t *testing.T) {
if test.src == "foo[*].bar" {
// Skip the test that's supposed to fail for splat syntax.
t.Skip("skipping test for unsupported splat syntax")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we test for this to error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, this is a copy-paste error which makes the message wrong. This test case is expecting an error, which is not what we want here. So I skip this test case in the test branch that does support splats, otherwise the test will fail expecting an error when there isn't one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this shortly!

Copy link
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. The behavior is entirely opt-in, and only used from within Terraform, so we should be able to control its use internally.

Copy link
Collaborator

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, I think!

The "compare test.src and maybe skip" pattern feels like a minor comprehension hazard for our future selves, but I'm probably over-optimizing; if it's only ever gonna be a couple of tests involved, I won't sweat it.

@liamcervante liamcervante merged commit f7cd61a into main Apr 22, 2024
13 checks passed
@liamcervante liamcervante deleted the liamcervante/parse-partial-traversal branch April 22, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants