Skip to content

Commit

Permalink
cleanup unit test files
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Dec 4, 2020
1 parent 7dc25e7 commit ecab404
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 104 deletions.
13 changes: 3 additions & 10 deletions spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@
)
}

if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'virtuozzolinux-7-x86_64'].include?(os)
# 'archlinux-5-x86_64' got removed from that list. It has systemd, but we use the repo packages and their shipped unit files.
# init_style = 'systemd'
if facts[:os]['name'] == 'Archlinux'

it { is_expected.not_to contain_systemd__unit_file('prometheus.service') }
else
it {
is_expected.to contain_class('systemd')
}
Expand Down Expand Up @@ -137,13 +137,6 @@
}
end
end
elsif os == 'archlinux-5-x86_64'

it { is_expected.not_to contain_systemd__unit_file('prometheus.service') }
else
it {
is_expected.to raise_error(Puppet::Error, %r{I don't know how to create an init script for style})
}
end

it {
Expand Down
58 changes: 28 additions & 30 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,40 @@
facts.merge(os_specific_facts(facts))
end

[{ version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url' }].each do |parameters|
context "with parameters #{parameters}" do
let(:params) do
parameters
end
parameters = { version: '2.0.0-rc.1', bin_dir: '/usr/local/bin', install_method: 'url', init_style: 'systemd', configname: 'prometheus.yaml' }

context "with parameters #{parameters}" do
let(:params) do
parameters
end

prom_version = parameters[:version] || '1.5.2'
prom_major = prom_version[0]
it { is_expected.to contain_class('systemd') }

it {
is_expected.to contain_systemd__unit_file('prometheus.service').with(
'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd"))
)
}

if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64'].include?(os)
prom_version = parameters[:version] || '1.5.2'
prom_major = prom_version[0]
describe 'max_open_files' do
context 'by default' do
it {
is_expected.to contain_class('systemd')
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).not_to include('LimitNOFILE')
}
end

context 'when set to 1000000' do
let(:params) do
super().merge('max_open_files' => 1_000_000)
end

it {
is_expected.to contain_systemd__unit_file('prometheus.service').with(
'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd"))
)
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).to include('LimitNOFILE=1000000')
}
describe 'max_open_files' do
context 'by default' do
it {
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).not_to include('LimitNOFILE')
}
end
context 'when set to 1000000' do
let(:params) do
parameters.merge('max_open_files' => 1_000_000)
end

it {
content = catalogue.resource('systemd::unit_file', 'prometheus.service').send(:parameters)[:content]
expect(content).to include('LimitNOFILE=1000000')
}
end
end
end
end
end
Expand Down
85 changes: 21 additions & 64 deletions spec/defines/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,77 +91,32 @@
it { is_expected.to contain_archive("/tmp/smurf_exporter-#{parameters[:version]}.tar.gz").with_extract_path('/opt/foo') }
end

if ['centos-7-x86_64', 'centos-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'ubuntu-20.04-x86_64', 'archlinux-5-x86_64', 'virtuozzolinux-7-x86_64'].include?(os)
# init_style = 'systemd'
it { is_expected.to contain_class('systemd') }

it { is_expected.to contain_class('systemd') }

it {
is_expected.to contain_systemd__unit_file('smurf_exporter.service').that_notifies(
'Service[smurf_exporter]'
).with_content(
%r{User=smurf_user\n}
).with_content(
%r{ExecStart=/usr/local/bin/smurf_exporter\n\nExecReload=}
)
}

if Gem::Version.new(facts[:puppetversion]) < Gem::Version.new('6.1.0')
it { is_expected.to contain_class('systemd::systemctl::daemon_reload').that_comes_before('Service[smurf_exporter]') }
end
it {
is_expected.to contain_systemd__unit_file('smurf_exporter.service').that_notifies(
'Service[smurf_exporter]'
).with_content(
%r{User=smurf_user\n}
).with_content(
%r{ExecStart=/usr/local/bin/smurf_exporter\n\nExecReload=}
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end
if Gem::Version.new(facts[:puppetversion]) < Gem::Version.new('6.1.0')
it { is_expected.to contain_class('systemd::systemctl::daemon_reload').that_comes_before('Service[smurf_exporter]') }
end

it {
is_expected.to contain_systemd__unit_file('smurf_exporter.service').with_content(
%r{ExecStart=/usr/local/bin/notsmurf_exporter}
)
}
context 'with overidden bin_name' do
let(:params) do
super().merge(bin_name: 'notsmurf_exporter')
end

elsif ['ubuntu-14.04-x86_64'].include?(os)
# init_style = 'upstart'

it {
is_expected.to contain_file('/etc/init/smurf_exporter.conf').with(
'mode' => '0444',
'owner' => 'root',
'group' => 'root'
).with_content(
%r{env USER=smurf_user\n}
).with_content(
%r{exec start-stop-daemon -c \$USER -g \$GROUP -p \$PID_FILE -x \$DAEMON -S -- \n\nend script}
)
}

it {
is_expected.to contain_file('/etc/init.d/smurf_exporter').with(
'ensure' => 'link',
'target' => '/lib/init/upstart-job',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
is_expected.to contain_systemd__unit_file('smurf_exporter.service').with_content(
%r{ExecStart=/usr/local/bin/notsmurf_exporter}
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end

it {
is_expected.to contain_file('/etc/init/smurf_exporter.conf').with_content(
%r{env DAEMON=/usr/local/bin/notsmurf_exporter}
)
}
end
else
it {
is_expected.to raise_error(Puppet::Error, %r{I don't know how to create an init script for style})
}
end

if os == 'ubuntu-16.04-x86_64'
Expand All @@ -174,7 +129,7 @@
%r{SOMEVAR="42"\n}
)
}
elsif ['centos-6-x86_64', 'redhat-6-x86_64', 'centos-7-x86_64', 'redhat-7-x86_64'].include?(os)
elsif ['centos-7-x86_64', 'redhat-7-x86_64'].include?(os)
it {
is_expected.to contain_file('/etc/sysconfig/smurf_exporter').with(
'mode' => '0644',
Expand All @@ -193,6 +148,7 @@
'enable' => true
)
}

context 'exported resources' do
subject { exported_resources }

Expand All @@ -206,6 +162,7 @@
end
end
end

context 'with scrape_job_labels specified' do
let(:params) do
{
Expand Down

0 comments on commit ecab404

Please sign in to comment.