Repository navigation
test: modernize the RSpec suite and cover the workflow logic - #44
Merged
Merged
Conversation
The spec_helper was an empty license header: no requires, no RSpec configuration, and nothing in `.rspec` to load it. Every spec file had to require its own dependencies, and none of the guardrails that catch stale tests were switched on. This wires the suite up properly: - `.rspec` now passes `--require spec_helper`, so the helper is the single place that loads the driver and its Test Kitchen dummies. - `spec_helper` turns on `verify_partial_doubles`, `disable_monkey_patching!`, expect-only syntax, `raise_errors_for_deprecations!`, and random ordering with a printed seed. - `spec/support/vro_doubles.rb` builds verifying doubles for the slice of the vcoworkflows API the driver touches, so a rename upstream fails the suite instead of passing against a stub that no longer matches. - Specs are no longer excluded from cookstyle, so they are held to the same style as `lib/`. It also fills in the logic the old suite left uncovered. Previously `#create` and `#destroy` were only checked by stubbing the driver's own methods and asserting they were called, which proves nothing about what the driver actually sends to vRO. There are now end-to-end examples that stub only at the `VcoWorkflows::Workflow` boundary and assert the real behaviour: which workflow gets looked up, that configured create and destroy parameters are pushed to it, that `server_id` reaches the destroy workflow, and that the create output lands in instance state. New coverage for the branches where bugs can hide: - the poll loop in `#wait_for_workflow` -- how many times the token is re-read, that it sleeps two seconds between polls, that it does not sleep when the run is already finished, and that a real elapsed timeout fires - `request_timeout` appearing in the timeout message when it is not the default - `#set_workflow_parameters` stringifying symbol keys, passing non-string values through, and no-opping on an empty hash - `#output_parameter_value` stringifying numbers and unset values - `vro_disable_ssl_verify` reaching `VcoWorkflows::Config` - `#execute_create_workflow` not validating or writing state when the run failed - memoization of `vro_config`, `vro_client`, and `output_parameters` Also removes a `Struct.new` assigned to a top-level constant inside an example, which leaked a constant into the whole suite and warned on redefine, and corrects the spec path in CONTRIBUTING.md. 51 examples became 77. Signed-off-by: Tim Smith <tim@mondoo.com>
webmock has never been required or used by anything in spec/ -- the specs stub the vcoworkflows client rather than the HTTP layer underneath it, so nothing ever reaches a socket for webmock to intercept. Removing it also clears the one thing standing between this repo and a green lint run: cookstyle 9.0.0 flags the extra spacing in that Gemfile line under Layout/ExtraSpacing, which cookstyle 8 did not, so `main` went red on its own the moment cookstyle 9 shipped. Signed-off-by: Tim Smith <tim@mondoo.com>
Member
Author
|
Pushed an extra commit dropping the unused |
…res (#45) A handful of related problems in the create/destroy lifecycle. `destroy` never removed `server_id` and `hostname` from the state hash. Test Kitchen writes state back in an `ensure` block even when an action fails, so when `wait_for_server` gives up and tears the machine down, the state file is still left naming a server that no longer exists. The next `kitchen destroy` then runs the destroy workflow a second time against a machine that is already gone. `destroy` now clears both keys once the workflow succeeds, which also makes it a no-op the second time it is called in a process. `wait_for_server` replaced the connection failure with whatever the cleanup raised. If the machine was unreachable *and* the destroy workflow then failed, the user saw the vRO error and no hint of why the machine was being destroyed in the first place. The cleanup failure is now logged -- including a warning that the server may have been left behind -- and the original connection failure is what propagates. `set_workflow_vars` cleared the memoized client but not the memoized output parameters, so anything reading `output_parameters` after switching from the create workflow to the destroy workflow would still be looking at the create workflow's output. `output_parameter_value` raised `NoMethodError` on nil for any parameter the workflow did not return, which made `output_parameter_empty?` blow up instead of answering the question it was asked. It now returns an empty string for a missing parameter. That in turn removes a dead branch: `output_parameter_empty?` tested `.nil?` on the result of a `.to_s`, which can never be nil, and computed the value twice to do it. Also requires `timeout` explicitly rather than relying on a dependency having pulled it in, and updates a `rubocop:disable` comment that still used the old `Style/AccessorMethodName` namespace -- cookstyle printed a deprecation warning about it on every run. Signed-off-by: Tim Smith <tim@mondoo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
spec/spec_helper.rbwas an empty license header — no requires, noRSpec.configure, and nothing in.rspecto load it. Every spec file had to require its own dependencies, and none of the guardrails that catch stale tests were on.This wires the suite up the way the rest of our drivers do:
.rspecpasses--require spec_helper, so the helper is the single place that loads the driver and its Test Kitchen dummies.spec_helperturns onverify_partial_doubles,disable_monkey_patching!, expect-only syntax,raise_errors_for_deprecations!, and random ordering with a printed seed.spec/support/vro_doubles.rbbuilds verifying doubles for the slice of the vcoworkflows API this driver touches. If vcoworkflows renamestokenor dropsoutput_parameters, the suite fails instead of passing against a stub that no longer matches the real object.lib/.Coverage
The old suite checked
#createand#destroyby stubbing the driver's own methods and asserting they were called. That proves the methods call each other; it proves nothing about what we actually send to vRO. There are now end-to-end examples that stub only at theVcoWorkflows::Workflowboundary and assert the real behaviour: which workflow gets looked up, that configured create and destroy parameters are pushed to it, thatserver_idreaches the destroy workflow, and that create output lands in instance state.New coverage aimed at the branches where bugs actually hide:
#wait_for_workflow— how many times the token is re-read, that it sleeps two seconds between polls, that it does not sleep when the run has already finished, and that a real elapsed timeout firesrequest_timeoutshowing up in the timeout message when it is not the default#set_workflow_parametersstringifying symbol keys, passing non-string values through, and no-opping on an empty hash#output_parameter_valuestringifying numbers and unset valuesvro_disable_ssl_verifyreachingVcoWorkflows::Config#execute_create_workflowneither validating output nor writing state when the run failedvro_config,vro_client, andoutput_parametersAlso drops a
Struct.newassigned to a top-level constant inside an example — it leaked a constant into the whole suite and warned on redefinition — and corrects the spec path inCONTRIBUTING.md, which pointed at a file that does not exist.No change to
lib/. 51 examples became 77.Verification