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

Further simplify enumeration of attached disks for VMware VMX builder #6440

Merged
merged 1 commit into from
Jul 12, 2018
Merged

Further simplify enumeration of attached disks for VMware VMX builder #6440

merged 1 commit into from
Jul 12, 2018

Conversation

DanHam
Copy link
Contributor

@DanHam DanHam commented Jul 1, 2018

This PR:

  • Collates separate regexp's into one for greater efficiency
  • Inlines the internals of the getAttachedDisk function as we no longer need to call for separate adapter types
  • Removes the now defunct struct and variables

This should probably have gone in with #6229 so apologies for the repeat. However, I didn't really see it then for what ever reason. I've kept the rather lengthy comment in there to explain the regexp/background...

As usual, feedback and suggestions for improvement are welcome

* Collate separate regexp's into one for greater efficiency
* Inline function and remove unnecessary struct and variables
@DanHam DanHam requested a review from a team as a code owner July 1, 2018 15:58
@SwampDragons
Copy link
Contributor

I like the simplification of the regex, so thanks for this. What do you think about keeping getAttachedDisks as a helper function and actually writing some tests to validate the regex/document what it's looking for?

@DanHam
Copy link
Contributor Author

DanHam commented Jul 3, 2018

I kind of prefer the function 'inline' as opposed to keeping it as a helper function. I guess it just looks/feels cleaner to me - we're not calling that piece of code multiple times any more so I felt the function wasn't needed any more.

I do see your point, that having a separate, testable function has some value. That said, we're not too bad with our test coverage for step_clone_vmx.go - 78.4%. The coverage report clearly highlights some of the bits we've not covered (grab the raw html report HERE). Clearly we should be testing those bits, so if you're happy for me to proceed on this basis, I'll have a go a refactoring the tests to get those highlighted elements covered off.

I'm wondering if I should try and move my monster comment/explanation of the 'why' behind the regex into the test file instead. What do you think?

@SwampDragons
Copy link
Contributor

I can respect that; normally I don't like making tiny functions for things that are only done once either. That said, I'd like tests for this regex more than I'd like the elegance of having it inline. Looking over step_clone_vmx_test.go I'm not seeing anything that tests how we create the diskFileNames slice. The more obscure the code (and I think most of us find RegExes fairly hard to read) the more I like some kind of sanity test around them. We should have probably added this test a while ago; but now it feels kind of necessary. If you can find a way to test that the regex parses out what we expect without pulling it into a separate function, I'd be open to that too.

@DanHam
Copy link
Contributor Author

DanHam commented Jul 12, 2018

I'm not seeing anything that tests how we create the diskFileNames slice.

So the diskFilenames slice created using that regex gets written into the diskFullPaths slice HERE

We then store diskFullPaths in the statebag as disk_full_paths HERE

We then test disk_full_paths is set and meets with expectations HERE

So the 'correctness' of the diskFileNames slice, and the regex used to set its contents, is tested via the checks we make on the value of disk_full_paths...

@SwampDragons
Copy link
Contributor

facepalm yep I was reading this backwards. I saw the test code generating the diskFullPaths variable and didn't realize it was just being used as the "expected", not as an input to the test. This is fine. Thanks for bearing with me.

@SwampDragons SwampDragons merged commit 1d15f09 into hashicorp:master Jul 12, 2018
@DanHam DanHam deleted the simplify-vmx-find-disks branch July 13, 2018 10:08
@ghost
Copy link

ghost commented Mar 31, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants