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

Modernize the acceptance tests #438

Merged
merged 4 commits into from
Feb 17, 2024

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Feb 7, 2022

This takes the lessons from rubocop/rubocop-rspec#1231 and applies them here.

Comment on lines +3 to +11
RSpec::Matchers.define_negated_matcher :execute_without_warning, :execute_with_warning

# systcl settings are untestable in docker
describe 'redis::administration', unless: default['hypervisor'] =~ %r{docker} do
it 'runs successfully' do
pp = <<-EOS
include redis
include redis::administration
EOS
def execute_with_warning
have_attributes(stderr: %r{WARNING})
end
Copy link
Member Author

Choose a reason for hiding this comment

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

This here is to combine things with .and since you can't use .not_to().and().

@ekohl
Copy link
Member Author

ekohl commented Feb 7, 2022

Updated to top the Debian backport acceptance test. See that commit for details.

@ekohl
Copy link
Member Author

ekohl commented Feb 7, 2022

I had one copy-paste error where .not_to was replaced by .to. Fixed that.

it { is_expected.not_to be_running }
end
specify { expect(package(redis_name)).not_to be_installed }
specify { expect(service(redis_name)).not_to be_enabled.and be_running }
Copy link

Choose a reason for hiding this comment

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

This line confuses me. As mentioned in the comment above - isn't not_to ...and disallowed in RSpec in some way?

Copy link

Choose a reason for hiding this comment

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

Alright, here it is:

        `expect(...).not_to matcher.and matcher` is not supported, since it creates a bit of an ambiguity. Instead, define negated versions of whatever matchers you wish to negate with `RSpec::Matchers.define_negated_matcher` and use `expect(...).to matcher.and matcher`.

I'd suggest either matching against a negated predicate if it exists (disabled? and stopped?) with a regular .to runner:

specify { expect(service(redis_name)).to be_disabled.and be_stopped }

If those predicates are not available on what service returns, define negated matchers for be_running and be_enabled.

Or just plain split this expectation in two:

specify do
  expect(service(redis_name)).not_to be_enabled
  expect(service(redis_name)).not_to be_running
end

Whatever you like the most.

Copy link
Member

Choose a reason for hiding this comment

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

Two different tests is much easier to read and maintain.

Copy link

Choose a reason for hiding this comment

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

I suppose you meant two spec examples.
Sure, I agree, unless expensive setup is involved, which I've heard, is sometimes the case with serverspec.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're absolutely right that this line is vague and confusing.

It is very common to always want it both enabled and running or both disabled and stopped. I've been wondering if it makes sense to have some short hand for it, but I struggled to find a good name for it.

Looking at https://serverspec.org/resource_types.html#service there is no be_disabled nor be_stopped. I'll think a bit more about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I went with the recommendation to split it in two statements. That was the easiest.

For example, not_to be_running is clear. But is to be_stopped the same? to be_stopped could imply it should be present but stopped while not_to be_running doesn't care whether the service is present or not. Splitting it in two avoids these issues.

@ekohl
Copy link
Member Author

ekohl commented Feb 22, 2022

I think this should be good to merge. I'm leaning to dropping Archlinux from the metadata for now since the tests obviously fail. Also #439 suggests it's entirely broken at the moment.

Copy link
Member

@bastelfreak bastelfreak left a comment

Choose a reason for hiding this comment

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

I'm fine with dropping Arch Linux from the metadata.json for now, or merging this as is.

@ekohl
Copy link
Member Author

ekohl commented Feb 25, 2022

That would be #441. I still think the changed in this PR that relate to Arch are good to keep in. Those are in separate commits so easy to distinguish.

@pirj do you think this is now all good to merge?

@vox-pupuli-tasks
Copy link

Dear @ekohl, thanks for the PR!

This is Vox Pupuli Tasks, your friendly Vox Pupuli GitHub Bot. I noticed that your pull request contains merge conflict. Can you please rebase?

You can find my sourcecode at voxpupuli/vox-pupuli-tasks

@zilchms
Copy link
Contributor

zilchms commented Feb 16, 2024

2 year ping @ekohl :) do you want to rebase this to the current master?

Archlinux doesn't have an AIO installation so the puppet_gem provider
doesn't work. Using the regular gem provider should work. The
aio_agent_version fact is used to determine whether it's an AIO install.
Originally introduced in 63251bc.
However, on current Debian systems the /var/run/redis directory is no
longer shared. bc37527 took care of
that. The versions that affect are no longer from backports anyway.

Fixes: bc37527
@ekohl ekohl force-pushed the modernize-acceptance-tests branch 2 times, most recently from 40e6d9d to 9f7c674 Compare February 16, 2024 18:43
@ekohl
Copy link
Member Author

ekohl commented Feb 16, 2024

Rebased to resolve merge conflicts. I didn't run it locally yet, so it may have broken something in the rebase.

Copy link
Contributor

@zilchms zilchms left a comment

Choose a reason for hiding this comment

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

I dont know if we want to fix the legacy facts in this PR or do all legacy stuff in a second one. Additionally we should look at why the Puppet 7 on Centos 8 test times out.
Otherwise this looks good :)

@ekohl
Copy link
Member Author

ekohl commented Feb 16, 2024

Additionally we should look at why the Puppet 7 on Centos 8 test times out.

It's common for the CentOS 8 tests to time out. I suspect pulling from quay.io may cause problems.

@ekohl
Copy link
Member Author

ekohl commented Feb 17, 2024

Updated to drop legacy facts in the test suite.

@zilchms zilchms merged commit e8ca35a into voxpupuli:master Feb 17, 2024
22 checks passed
@evgeni evgeni added the enhancement New feature or request label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants