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

Find Importers: Add missing break in relative paths logic #785

Merged
merged 3 commits into from
Nov 3, 2022

Conversation

julienduchesne
Copy link
Member

Jsonnet is weird with relative paths
Given two envs in their own folder. The two following imports in env1/main.jsonnet will work: ../env2/main.jsonnet and ../../env2/main.jsonnet, so we have to try all of them

The logic does so in a loop. Without a break, the logic worked when the match was found on the first case (and correct one) but failed on the second

Jsonnet is weird with relative paths
Given two envs in their own folder. The two following imports in `env1/main.jsonnet will work`: `../env2/main.jsonnet` and `../../env2/main.jsonnet`, so we have to try all of them

The logic does so in a loop. Without a `break`, the logic worked when the match was found on the first case (and correct one) but failed on the second
@julienduchesne julienduchesne requested a review from a team November 3, 2022 02:38
Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

Would it be possible to add a test case to validate this scenario?

@julienduchesne julienduchesne requested review from a team, jvrplmlmn, jjo and Duologic November 3, 2022 13:41
@julienduchesne
Copy link
Member Author

julienduchesne commented Nov 3, 2022

Re-requesting review. I changed the logic and added a test. Jsonnet does match relative paths deeper than expected but it's only one level

Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

I have cherry-picked the test (without the changes to pkg/jsonnet/find_importers.go) on top of main, and the test PASSes, but it should fail, right?

@julienduchesne
Copy link
Member Author

I have cherry-picked the test (without the changes to pkg/jsonnet/find_importers.go) on top of main, and the test PASSes, but it should fail, right?

Yeah, because there was another logic error 🤦. The .. were cutoff and not replaced by an absolute path: https://github.com/grafana/tanka/blob/main/pkg/jsonnet/find_importers.go#L170

But you're right, I think this requires a test that used to fail but now passes. I know how to do one. Let me do that now

@julienduchesne
Copy link
Member Author

I have cherry-picked the test (without the changes to pkg/jsonnet/find_importers.go) on top of main, and the test PASSes, but it should fail, right?

I added a test that does fail on the previous code, but now passes

Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

Just to make sure that I was not doing the partial cherry-picks locally to run the tests, I validated them with #786, which fails, as expected.

Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

👍

@julienduchesne
Copy link
Member Author

Thanks for the comments @jvrplmlmn! It helped find another bug and greatly improve the tests

@julienduchesne julienduchesne merged commit 5bc978b into main Nov 3, 2022
@julienduchesne julienduchesne deleted the julienduchesne/fix-importers-relative-paths branch November 3, 2022 14: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.

4 participants