-
Notifications
You must be signed in to change notification settings - Fork 597
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
Conversation
bb00f49
to
5fdb81b
Compare
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 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") |
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.
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?
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.
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.
hclsyntax/parse_traversal_test.go
Outdated
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") |
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.
Why don't we test for this to error?
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, 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.
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'll fix this shortly!
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 LGTM. The behavior is entirely opt-in, and only used from within Terraform, so we should be able to control its use internally.
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 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.
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.