Skip to content

Commit

Permalink
Rewrite spec tests
Browse files Browse the repository at this point in the history
This greatly refactors the tests to unify a lot. It uses a lot of
parameter inheritance to avoid duplication.
  • Loading branch information
ekohl authored and mmoll committed Nov 16, 2018
1 parent 76084c6 commit 15d6844
Show file tree
Hide file tree
Showing 25 changed files with 1,131 additions and 1,617 deletions.
16 changes: 4 additions & 12 deletions spec/classes/foreman_cli_discovery_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
require 'spec_helper'

describe 'foreman::cli::discovery' do
context 'on redhat-7-x86_64' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }
let(:pre_condition) { 'include foreman::cli' }

context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_discovery') }
end

context 'on debian-9-x86_64' do
let(:facts) do
on_supported_os['debian-9-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

let(:facts) { on_supported_os['debian-9-x86_64'] }
it { should contain_package('ruby-hammer-cli-foreman-discovery') }
end
end
9 changes: 4 additions & 5 deletions spec/classes/foreman_cli_openscap_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'spec_helper'

describe 'foreman::cli::openscap' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

it { should contain_package('tfm-rubygem-hammer_cli_foreman_openscap') }
context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_openscap') }
end
end
9 changes: 4 additions & 5 deletions spec/classes/foreman_cli_remote_execution_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'spec_helper'

describe 'foreman::cli::remote_execution' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

it { should contain_package('tfm-rubygem-hammer_cli_foreman_remote_execution') }
context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_remote_execution') }
end
end
122 changes: 58 additions & 64 deletions spec/classes/foreman_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
require 'spec_helper'

describe 'foreman::cli' do

on_os_under_test.each do |os, facts|
context "on #{os}" do
let :facts do facts end
let(:facts) { facts }

context 'standalone with parameters' do
let(:params) do {
'foreman_url' => 'http://example.com',
'username' => 'joe',
'password' => 'secret',
} end
let(:params) do
{
foreman_url: 'http://example.com',
username: 'joe',
password: 'secret'
}
end

it { is_expected.to compile.with_all_deps }
it { should contain_package('foreman-cli').with_ensure('installed') }

describe '/etc/hammer/cli.modules.d/foreman.yml' do
it 'should contain settings' do
verify_exact_contents(catalogue, '/etc/hammer/cli.modules.d/foreman.yml', [
":foreman:",
" :enable_module: true",
" :host: 'http://example.com'",
])
':foreman:',
' :enable_module: true',
" :host: 'http://example.com'"
])
end
end

Expand All @@ -30,83 +32,75 @@

it 'should contain settings' do
verify_exact_contents(catalogue, '/root/.hammer/cli.modules.d/foreman.yml', [
":foreman:",
" :username: 'joe'",
" :password: 'secret'",
" :refresh_cache: false",
" :request_timeout: 120",
])
':foreman:',
" :username: 'joe'",
" :password: 'secret'",
' :refresh_cache: false',
' :request_timeout: 120'
])
end
end

describe 'with manage_root_config=false' do
let(:params) do {
'foreman_url' => 'http://example.com',
'username' => 'joe',
'password' => 'secret',
'manage_root_config' => false,
} end

let(:params) { super().merge(manage_root_config: false) }
it { should_not contain_file('/root/.hammer') }
it { should_not contain_file('/root/.hammer/cli.modules.d/foreman.yml') }
end

context 'with ssl_ca_file' do
let(:params) do {
'foreman_url' => 'http://example.com',
'username' => 'joe',
'password' => 'secret',
'ssl_ca_file' => '/etc/ca.pub',
} end
let(:params) { super().merge(ssl_ca_file: '/etc/ca.pub') }

describe '/etc/hammer/cli.modules.d/foreman.yml' do
it 'should contain settings' do
verify_exact_contents(catalogue, '/etc/hammer/cli.modules.d/foreman.yml', [
":foreman:",
" :enable_module: true",
" :host: 'http://example.com'",
":ssl:",
" :ssl_ca_file: '/etc/ca.pub'",
])
':foreman:',
' :enable_module: true',
" :host: 'http://example.com'",
':ssl:',
" :ssl_ca_file: '/etc/ca.pub'"
])
end
end
end
end

context 'with foreman' do

context 'with settings from foreman' do
let :pre_condition do
"class { 'foreman':
admin_username => 'joe',
admin_password => 'secret',
server_ssl_chain => '/etc/puppetlabs/puppet/ssl/certs/ca.pub',
}"
<<-PUPPET
class { 'foreman':
admin_username => 'jane',
admin_password => 'supersecret',
foreman_url => 'https://foreman.example.com',
server_ssl_chain => '/etc/puppetlabs/puppet/ssl/certs/ca.pub',
}
PUPPET
end

it { should contain_package('foreman-cli').with_ensure('installed') }
it { is_expected.to compile.with_all_deps }
it do
should contain_package('foreman-cli')
.with_ensure('installed')
.that_subscribes_to('Class[foreman::repo]')
end

describe '/etc/hammer/cli.modules.d/foreman.yml' do
it 'should contain settings from foreman' do
verify_exact_contents(catalogue, '/etc/hammer/cli.modules.d/foreman.yml', [
":foreman:",
" :enable_module: true",
" :host: 'https://#{facts[:fqdn]}'",
":ssl:",
" :ssl_ca_file: '/etc/puppetlabs/puppet/ssl/certs/ca.pub'",
])
end
it 'should contain settings in /etc from foreman' do
verify_exact_contents(catalogue, '/etc/hammer/cli.modules.d/foreman.yml', [
':foreman:',
' :enable_module: true',
" :host: 'https://foreman.example.com'",
':ssl:',
" :ssl_ca_file: '/etc/puppetlabs/puppet/ssl/certs/ca.pub'"
])
end

describe '/root/.hammer/cli.modules.d/foreman.yml' do
it 'should contain settings from foreman' do
verify_exact_contents(catalogue, '/root/.hammer/cli.modules.d/foreman.yml', [
":foreman:",
" :username: 'joe'",
" :password: 'secret'",
" :refresh_cache: false",
" :request_timeout: 120",
])
end
it 'should contain settings in /root from foreman' do
verify_exact_contents(catalogue, '/root/.hammer/cli.modules.d/foreman.yml', [
':foreman:',
" :username: 'jane'",
" :password: 'supersecret'",
' :refresh_cache: false',
' :request_timeout: 120'
])
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions spec/classes/foreman_cli_tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'spec_helper'

describe 'foreman::cli::tasks' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

it { should contain_package('tfm-rubygem-hammer_cli_foreman_tasks') }
context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_tasks') }
end
end
9 changes: 4 additions & 5 deletions spec/classes/foreman_cli_templates_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'spec_helper'

describe 'foreman::cli::templates' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

it { should contain_package('tfm-rubygem-hammer_cli_foreman_templates') }
context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_templates') }
end
end
16 changes: 4 additions & 12 deletions spec/classes/foreman_cli_virt_who_configure_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
require 'spec_helper'

describe 'foreman::cli::virt_who_configure' do
context 'on redhat-7-x86_64' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }
let(:pre_condition) { 'include foreman::cli' }

context 'on redhat-7-x86_64' do
let(:facts) { on_supported_os['redhat-7-x86_64'] }
it { should contain_package('tfm-rubygem-hammer_cli_foreman_virt_who_configure') }
end

context 'on debian-9-x86_64' do
let(:facts) do
on_supported_os['debian-9-x86_64']
end

let(:pre_condition) { 'include foreman::cli' }

let(:facts) { on_supported_os['debian-9-x86_64'] }
it { should contain_package('ruby-hammer-cli-foreman-virt-who-configure') }
end
end
Loading

0 comments on commit 15d6844

Please sign in to comment.