Skip to content

Update the chef_helper to auto-type the chef tests

DJ Mountney requested to merge fix-lib-spec-before-polution into master

What does this MR do?

Makes it so the before block in chef_helper only applies to spec tests in the chef spec directory. This is done by auto-typing the tests in the chef directory, then scoping the before block to just these tests.

This fixes an before ordering issue that happens when lib only tests are loaded first.

To explain further:

The before block in chef_helper is setup with the intent that it runs first, and then more test specific before blocks would override it in each test. In order to do this, the tests require the chef_helper block. This works fine for the chef test. But our lib tests don't require chef_helper, and they aren't even expected any of the before work that the chef_helper has to have been run. So IF their tests are loaded first, their tests specific before block are loaded first, and then may be overwritten by the chef before block.

To test this you can run:

bundle exec rspec spec/lib/gitlab/tasks/license_spec.rb spec/chef/cookbooks/consul/recipes/consul_watcher_spec.rb

Without this MR, that test run fails the license spec tests. But if you run the license_spec tests alone, OR swap the order of the two files, it all passes.

Related issues

The security mirror had broken master pipelines due to this issue. Due to the license_tests being run first in that mirror until we busted the knapsack cache today (to get a different test order).

The license tests have a test that mocks the File.open method. But the chef_helper also has one that does that for the initial root password, and that ended up undoing the one meant for the license tests.

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com
  • Pipeline is green on dev.gitlab.org if the change is touching anything besides documentation or internal cookbooks
  • trigger-package has a green pipeline running against latest commit

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Tests added
  • Integration tests added to GitLab QA
  • Equivalent MR/issue for the GitLab Chart opened
Edited by DJ Mountney

Merge request reports

Loading