Skip to content

Commit

Permalink
Introduce a shared example to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Mar 17, 2022
1 parent d08c47f commit 8072d6a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 149 deletions.
92 changes: 2 additions & 90 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'spec_helper_acceptance'

describe 'basic installation' do
certdir = '/etc/pulpcore-certs'

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
Expand All @@ -11,79 +9,14 @@
end
end

describe user('pulp') do
it { is_expected.to exist }
its(:uid) { is_expected.to be < 1000 }
end

describe group('pulp') do
it { is_expected.to exist }
its(:gid) { is_expected.to be < 1000 }
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-api') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-resource-manager') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

describe service('pulpcore-worker@1') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe port(443) do
it { is_expected.to be_listening }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: "#{certdir}/ca-cert.pem") do
its(:response_code) { is_expected.to eq(200) }
its(:exit_status) { is_expected.to eq 0 }
end

describe command("PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager dumpdata auth.User") do
its(:stdout) { is_expected.to match(/auth\.user/) }
its(:exit_status) { is_expected.to eq 0 }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/", cacert: "#{certdir}/ca-cert.pem") do
its(:response_code) { is_expected.to eq(403) }
its(:exit_status) { is_expected.to eq 0 }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/",
cacert: "#{certdir}/ca-cert.pem", key: "#{certdir}/client-key.pem", cert: "#{certdir}/client-cert.pem") do
its(:response_code) { is_expected.to eq(200) }
its(:body) { is_expected.to contain('artifacts') }
its(:exit_status) { is_expected.to eq 0 }
end
include_examples 'the default pulpcore application'

describe command("PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager diffsettings") do
its(:exit_status) { is_expected.to eq 0 }
end
end

describe 'with content cache enabled' do
certdir = '/etc/pulpcore-certs'

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
Expand All @@ -94,23 +27,7 @@ class { 'pulpcore':
end
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe port(443) do
it { is_expected.to be_listening }
end
include_examples 'the default pulpcore application'

describe port(6379) do
it { is_expected.to be_listening }
Expand All @@ -125,9 +42,4 @@ class { 'pulpcore':
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: "#{certdir}/ca-cert.pem") do
its(:response_code) { is_expected.to eq(200) }
its(:exit_status) { is_expected.to eq 0 }
end
end
32 changes: 2 additions & 30 deletions spec/acceptance/plugins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,10 @@
end
end

include_examples 'the default pulpcore application'

describe file('/etc/pulp/settings.py') do
it { is_expected.to be_file }
its(:content) { is_expected.to match(/^TOKEN_AUTH_DISABLED=True$/) }
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-api') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-resource-manager') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: '/etc/pulpcore-certs/ca-cert.pem') do
its(:response_code) { is_expected.to eq(200) }
its(:exit_status) { is_expected.to eq 0 }
end

end
31 changes: 2 additions & 29 deletions spec/acceptance/use_pulp2_content_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,10 @@ class { 'pulpcore::plugin::rpm':
end
end

include_examples 'the default pulpcore application'

describe file('/etc/pulp/settings.py') do
it { is_expected.to be_file }
its(:content) { is_expected.to match(/^TOKEN_AUTH_DISABLED=True$/) }
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-api') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-resource-manager') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: '/etc/pulpcore-certs/ca-cert.pem') do
its(:response_code) { is_expected.to eq(200) }
its(:exit_status) { is_expected.to eq 0 }
end
end
69 changes: 69 additions & 0 deletions spec/support/acceptance/examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
shared_examples 'the default pulpcore application' do
certdir = '/etc/pulpcore-certs'

describe user('pulp') do
it { is_expected.to exist }
its(:uid) { is_expected.to be < 1000 }
end

describe group('pulp') do
it { is_expected.to exist }
its(:gid) { is_expected.to be < 1000 }
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-api') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-content') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('pulpcore-resource-manager') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end

describe service('pulpcore-worker@1') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe port(443) do
it { is_expected.to be_listening }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: "#{certdir}/ca-cert.pem") do
its(:response_code) { is_expected.to eq(200) }
its(:exit_status) { is_expected.to eq 0 }
end

describe command("PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager dumpdata auth.User") do
its(:stdout) { is_expected.to match(/auth\.user/) }
its(:exit_status) { is_expected.to eq 0 }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/", cacert: "#{certdir}/ca-cert.pem") do
# Requires authentication: https://github.com/pulp/pulpcore/issues/2340
its(:response_code) { is_expected.to eq(403) }
its(:exit_status) { is_expected.to eq 0 }
end

describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/",
cacert: "#{certdir}/ca-cert.pem", key: "#{certdir}/client-key.pem", cert: "#{certdir}/client-cert.pem") do
its(:response_code) { is_expected.to eq(200) }
its(:body) { is_expected.to contain('artifacts') }
its(:exit_status) { is_expected.to eq 0 }
end
end

0 comments on commit 8072d6a

Please sign in to comment.