-
Notifications
You must be signed in to change notification settings - Fork 72
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
(QENG-3370) Add pe_* value CLI override options. #21
Conversation
@doug-rosser how does this look? Also, please note that this patch still needs tests added. |
This may be necessary to ensure coverage checks can work correctly. Also, it makes sense to test at this since I know of at least one project that is doing something similar. Not so sure about the way this is handling stderr though--just trying to avoid polluting the minitest console output.
This script allows one to generate test fixtures using beaker-hostgenerator itself. Yay. The generated directory structure could use some more thought.
This will make it easier to generate many many fixtures.
Unclutters the fixture generator class and maintains distinction between test and helper methods.
end | ||
|
||
fixture_file = File.open(f, "r") | ||
fixture_hash = YAML.load(fixture_file) |
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.
Idiomatically, I would probably drop the temp file variable and go with:
fixture_hash = YAML.load_file(f)
or
fixture_hash = YAML.load(File.read(f))
(The "or" because I can't remember if load_file
is always available, may depend on YAML version or implementation).
OK, so the fixtures are used to snapshot the behavior of the generator at this point in time? |
options = fixture_hash["options_string"] | ||
options = options.split | ||
test_hash = run_cli_with_options(options) | ||
assert_equal(fixture_hash["expected_hash"], test_hash) |
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 is probably a good place to document (for instance via the 3rd argument to assert_equal
) what this failure means. I believe it means "the behavior of the generator has changed from the snapshotted behavior".
If that's true folks are also going to want guidance on how/when to re-snapshot things so that they can take the changed behavior as a new baseline.
* Move FixtureGenerator class into test/utils/generator_helpers.rb * Create generate:test Rake task
@rick yeah, snapshotting is a good way to describe it. I think I've addressed all your comments. I added a Unfortunately the tests stop running on the first assertion failure so I'm still not sure this is a particularly good way to write the |
This makes it possible to treat each individual fixture its own test case which improves the reporting and ensures that all fixtures are tested even if some fail. Using a loop containing an assertion in minitest did not work for this purpose because a failed assertion caused the loop to break prematurely; it probably would have been possible to catch whatever the exception was and continue the loop but whatever. I already did this.
@waynr The code looks good, but the old (weird) behavior is not present. Even though I think the usefulness is dubious, the old code (master branch) would set pe_dir if pe_family and pe_version were the same string. This new code doesn't preserve that behavior. Example:
|
Since the OSINFO and OSINFO_BHGv1 module constants are only initialized once (during library load), do not refer directly to them using reference variables. Instead, initialize the osinfo variable directly on each call of get_osinfo and merge in the module constants as appropriate based on the given beaker-hostenerator version integer. This bug never came up during normal command-line usage of beaker-hostgenerator because get_osinfo would never be expected to be called with both bhg_version=0 and bhg_version=1. However, it came up both during generation of test fixtures and validation of those test fixtures in rspec since the module is only loaded once which led to the mutated value of the OSINFO module constant to persist across all initializations of the BeakerHostGenerator::CLI class.
Similar to the BeakerHostGenerator::Data::Vmpooler data initialization bug, this is something that would not typically show up during normal command line usage of beaker-hostgenerator because at that time there is typically only one reference made to the BeakerHostGenerator::Utils module constant. However during test fixture generation and rspec tests the modules were only loaded once so there was only one attempt to read in environment variables which led to inconsisten results depending on the order in which the fixtures were generated/tested.
@doug-rosser okay, I've fixed that bug. The problem was here: aa3e08c#diff-0623c137fe4358c047889a4ff1adc01bL62 There were some other module constant initialization problems throughout the beaker-hostgenerator library that were leading to incorrectly-generated fixtures which have now been fixed. |
👍 👍 👍 |
@@ -0,0 +1 @@ | |||
-/vendor |
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 we want to commit an emacs file like this?
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 added it because I think of it as similar to a .gitignore
file which can often contain subjectively-named file paths. e.g. https://github.com/puppetlabs/beaker-hostgenerator/blob/master/.gitignore#L13-L14 (That .gitignore
originally came from puppetlabs/beaker-template)
The difference here is that I don't care as much about .gitignore
so I never bothered to add vendor
to it the way I do for projectile. Local package installation is much more annoying in projectile than in git.
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 would defer to you as far as whether you think it's a good idea or not--I haven't really thought through the implications for other emacs users. I'm sure there is some way to configure projectile exclude paths in one's emacs configuration which would addres my problem more generally.
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 think you want to add .projectile
to your global ~/.gitignore
, and then you can sprinkle these projectile ignore files anywhere.
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.
Alternately, you could just configure projectile to globally ignore vendor
directories with projectile-globally-ignored-directories
if that suits you better.
Either way I wouldn't think we'd want to start committing editor-specific files.
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.
Are you saying that I should remove this file from the PR? I don't have a problem with that, but just to clarify I intentially added it in the first place.
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.
Ha yeah I'd say remove it from the PR and achieve what you're trying to do using one of the options I mentioned above.
But this is a good idea, I'm going to ignore vendor directories too 😄
This reverts commit 3dd4eb3.
`generate:fixtures` task: | ||
|
||
- When you modify the `FixtureGenerator` to generate new fixtures. | ||
- When you need to fix bug (generated hosts are not usable without your change, |
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.
💄 "fix a bug"
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.
Fixed!
@@ -21,6 +21,8 @@ group :acceptance_testing do | |||
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 2.0') | |||
end | |||
|
|||
gem "minitest" |
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.
Should this be under a test or development group so it's not required for normal usage?
👍 - left some minor nitpicks |
# namespace-named default tasks. | ||
# these are the default tasks invoked when only the namespace is referenced. | ||
# they're needed because `task :default` in those blocks doesn't work as expected. | ||
task 'test:spec' => 'test:spec:run' | ||
task 'test:spec' => ['test:spec:run', 'test:spec:minitest'] |
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.
shouldn't :generate:fixtures be a dependency of this task?
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, see the documentation at:
https://github.com/puppetlabs/beaker-hostgenerator/blob/qeng-3370/README.md#generated-fixtures
The fixture generator is not meant to be run every time the tests are run--that's why the fixtures are committed to the repo, to "snapshot" the current behavior of beaker-hostgenerator in a way that helps prevent regressions as we refactor or repurpose parts of the code.
Anyway, we generated fixtures before every time we run the specs that use those fixtures that spec would always pass unless we do something complicated to generate the fixtures for some older commit of the repo then test using them against the HEAD of the PR branch (which would assume a certain CI setup).
PE_UPGRADE_VERSION=ENV['pe_upgrade_version'] | ||
PE_UPGRADE_FAMILY=ENV['pe_upgrade_family'] | ||
def pe_version | ||
ENV['pe_version'] |
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 we want to memoize calls to the environment here or do we expect these values to change?
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.
We expect these values to change in the context of both test fixture generation and test fixture validation:
https://github.com/puppetlabs/beaker-hostgenerator/blob/qeng-3370/spec/beaker-hostgenerator/generator_spec.rb#L106-L113
https://github.com/puppetlabs/beaker-hostgenerator/blob/qeng-3370/test/util/generator_helpers.rb#L34-L40
Otherwise I probably would probably hate Ruby slightly less right now.
In general this looks like a good change and it has great documentation and automation around it. However, I usually consider fixture/data driven testing like this an anti-pattern. I think it has a valuable place when you have legacy behavior around spaghetti code that is hard to test otherwise, or you have folks writing tests that may not be familiar with the code under test and/or development in general. I would prefer testing the logic in the code not the variations in the data. Having said that, that's the only thing I have an issue with, and it would appear from the previous comments that I'm in the minority, just felt obligated to mention it. All in all, 👍 |
(QENG-3370) Add pe_* value CLI override options.
justin has a good point about what appears to be feature level testing. i'm okay with that. maybe should move to an integration suite, and unit tests should be added for unit/class/module logic |
This should have been changed in commit c6507fd (voxpupuli#21).
No description provided.