Skip to content

Commit

Permalink
Merge pull request #192 from ekohl/add-acceptance-tests
Browse files Browse the repository at this point in the history
Add basic acceptance tests for the existing examples
  • Loading branch information
bastelfreak committed Jul 18, 2024
2 parents b7b229a + 442bd7e commit 581139a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ concurrency:
jobs:
puppet:
name: Puppet
uses: voxpupuli/gha-puppet/.github/workflows/basic.yml@v2
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Gemfile:
optional:
':test':
- gem: webmock
spec/spec_helper_acceptance.rb:
unmanaged: false
6 changes: 3 additions & 3 deletions examples/x509_cert.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
openssl::certificate::x509 { 'foo.bar':
openssl::certificate::x509 { 'foo.example.com':
ensure => present,
country => 'CH',
organization => 'Example.com',
commonname => $fqdn,
commonname => 'foo.example.com',
base_dir => '/tmp',
owner => 'www-data',
owner => 'nobody',
password => 'mahje1Qu',
}
9 changes: 9 additions & 0 deletions spec/acceptance/dhparam_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'x509_cert example' do
it_behaves_like 'the example', 'dhparam.pp' do
it { expect(file('/etc/ssl/certs/dhparam.pem')).to be_file }
end
end
24 changes: 24 additions & 0 deletions spec/acceptance/x509_cert_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

# the openssl output changed and differs between EL9 vs older versions
# https://github.com/mizzy/serverspec/commit/ac366dd40015f0b53e70a3ed881b931dfc83c603 might not be a correct fix
# Ewoud is working on a fix in https://github.com/ekohl/serverspec/commit/64874e9c8cc70b097300c3a60281572a3528768e
# in the meantime we won't use x509_certificate matcher
describe 'x509_cert example' do
it_behaves_like 'the example', 'x509_cert.pp' do
it { expect(file('/tmp/foo.example.com.crt')).to be_file.and(have_attributes(owner: 'nobody')) }
# it { expect(x509_certificate('/tmp/foo.example.com.crt')).to be_certificate.and(have_attributes(subject: 'C = CH, O = Example.com, CN = foo.example.com')) }

describe x509_certificate('/tmp/foo.example.com.crt') do
it { is_expected.to be_certificate }
it { is_expected.to be_valid }
its(:subject) { is_expected.to match_without_whitespace(%r{C = CH, O = Example.com, CN = foo.example.com}) }
its(:keylength) { is_expected.to eq 3072 }
end

it { expect(file('/tmp/foo.example.com.key')).to be_file.and(have_attributes(owner: 'nobody', mode: '600')) }
it { expect(x509_private_key('/tmp/foo.example.com.key', passin: 'pass:mahje1Qu')).to have_matching_certificate('/tmp/foo.example.com.crt') }
end
end
23 changes: 6 additions & 17 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# frozen_string_literal: true

require 'beaker-pe'
require 'beaker-puppet'
require 'puppet'
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'
require 'beaker-task_helper'
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

run_puppet_install_helper
configure_type_defaults_on(hosts)
install_ca_certs unless pe_install?
# install_bolt_on(hosts) unless pe_install?
install_module_on(hosts)
install_module_dependencies_on(hosts)
require 'voxpupuli/acceptance/spec_helper_acceptance'

RSpec.configure do |c|
c.formatter = :documentation
end
configure_beaker(modules: :metadata)

Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f }
13 changes: 13 additions & 0 deletions spec/support/acceptance/matchers/match_without_whitespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# based on https://github.com/theforeman/puppet-certs/blob/master/spec/support/acceptance/matchers/match_without_whitespace.rb
# https://github.com/theforeman/puppet-certs/commit/6b82334a5661a4e95b8c0604535ec39c991c9787
RSpec::Matchers.define :match_without_whitespace do |expected|
match do |actual|
actual.gsub(%r{\s*}, '').match?(Regexp.new(expected.source, Regexp::EXTENDED))
end

failure_message do |actual|
"Actual:\n\n\s\s#{actual.gsub(%r{\s*}, '')}\n\nExpected:\n\n\s\s#{expected.source}"
end
end

0 comments on commit 581139a

Please sign in to comment.