Skip to content

Commit

Permalink
Refactor unit tests (and drop upstart support)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Bushmelev committed Nov 25, 2024
1 parent dd9200d commit 2e1bfb5
Show file tree
Hide file tree
Showing 7 changed files with 603 additions and 927 deletions.
12 changes: 0 additions & 12 deletions .rubocop_todo.yml

This file was deleted.

26 changes: 9 additions & 17 deletions manifests/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@
Enum['none','log'] $log = 'none',
Boolean $enable_cli_and_http = false,
) {
if $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '15.04') < 0 {
file { 'aptly-upstart':
path => '/etc/init/aptly-api.conf',
content => template('aptly/etc/aptly-api.init.erb'),
notify => Service['aptly-api'],
}
} else {
file { 'aptly-systemd':
path => '/etc/systemd/system/aptly-api.service',
content => template('aptly/etc/aptly-api.systemd.erb'),
}
~> exec { 'aptly-api-systemd-reload':
command => 'systemctl daemon-reload',
path => ['/usr/bin', '/bin', '/usr/sbin'],
refreshonly => true,
notify => Service['aptly-api'],
}
file { 'aptly-systemd':
path => '/etc/systemd/system/aptly-api.service',
content => template('aptly/etc/aptly-api.systemd.erb'),
}
~> exec { 'aptly-api-systemd-reload':
command => 'systemctl daemon-reload',
path => ['/usr/bin', '/bin', '/usr/sbin'],
refreshonly => true,
notify => Service['aptly-api'],
}

service { 'aptly-api':
Expand Down
256 changes: 41 additions & 215 deletions spec/classes/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,248 +3,74 @@
require 'spec_helper'

describe 'aptly::api' do
context 'Using Systemd' do
let(:facts) do
{
operatingsystem: 'Debian',
operatingsystemrelease: '8.7',
os: {
architecture: 'amd64',
distro: {
codename: 'stretch',
description: 'Debian GNU/Linux 9.4 (stretch)',
id: 'Debian',
release: {
full: '9.4',
major: '9',
minor: '4'
}
},
family: 'Debian',
hardware: 'x86_64',
name: 'Debian',
release: {
full: '9.4',
major: '9',
minor: '4'
},
selinux: {
enabled: false
}
}
}
end

context 'param defaults' do
let(:params) { {} }

it do
is_expected.to contain_file('aptly-systemd').
with_path('/etc/systemd/system/aptly-api.service').
without_content(%r{^\s*author }).
with_content(%r{^User=root$}).
with_content(%r{^Group=root$}).
with_content(%r{^ExecStart=/usr/bin/aptly api serve -listen=:8080$}).
that_notifies('Service[aptly-api]')
end

it do
is_expected.to contain_service('aptly-api').
with_ensure('running').
with_enable(true)
end
end

describe 'ensure' do
context 'present (default)' do
let(:params) { {} }

it { is_expected.to contain_service('aptly-api').with_ensure('running') }
end

context 'stopped' do
let(:params) do
{
ensure: 'stopped'
}
on_supported_os.each do |os, facts|
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) { facts }

context 'param defaults' do
it do
is_expected.to contain_file('aptly-systemd').
with_path('/etc/systemd/system/aptly-api.service').
without_content(%r{^\s*author }).
with_content(%r{^User=root$}).
with_content(%r{^Group=root$}).
with_content(%r{^ExecStart=/usr/bin/aptly api serve -listen=:8080$}).
that_notifies('Service[aptly-api]')
end

it { is_expected.to contain_service('aptly-api').with_ensure('stopped') }
end
end

describe 'user' do
context 'custom' do
let(:params) do
{
user: 'yolo'
}
it do
is_expected.to contain_service('aptly-api').
with_ensure('running').
with_enable(true)
end

it { is_expected.to contain_file('aptly-systemd').with_content(%r{^User=yolo$}) }
end
end

describe 'group' do
context 'custom' do
let(:params) do
{
group: 'yolo'
}
describe 'ensure' do
context 'present (default)' do
it { is_expected.to contain_service('aptly-api').with_ensure('running') }
end

it { is_expected.to contain_file('aptly-systemd').with_content(%r{^Group=yolo$}) }
end
end
context 'stopped' do
let(:params) { { ensure: 'stopped' } }

describe 'listen' do
context 'custom' do
let(:params) do
{
listen: '127.0.0.1:9090'
}
it { is_expected.to contain_service('aptly-api').with_ensure('stopped') }
end

it { is_expected.to contain_file('aptly-systemd').with_content(%r{^ExecStart=/usr/bin/aptly api serve -listen=127.0.0.1:9090$}) }
end
end

describe 'enable_cli_and_http' do
context 'false (default)' do
it { is_expected.to contain_file('aptly-systemd').without_content(%r{ -no-lock}) }
end
describe 'user' do
context 'custom' do
let(:params) { { user: 'yolo' } }

context 'true' do
let(:params) do
{
enable_cli_and_http: true
}
it { is_expected.to contain_file('aptly-systemd').with_content(%r{^User=yolo$}) }
end

it { is_expected.to contain_file('aptly-systemd').with_content(%r{ -no-lock}) }
end
end
end

context 'Using Upstart' do
let(:facts) do
{
operatingsystem: 'Ubuntu',
operatingsystemrelease: '15.03',
os: {
name: 'Ubuntu',
release: {
full: '15.03'
}
}
}
end

context 'param defaults' do
let(:params) { {} }

it do
is_expected.to contain_file('aptly-upstart').
with_path('/etc/init/aptly-api.conf').
without_content(%r{^\s*author }).
with_content(%r{^setuid root$}).
with_content(%r{^setgid root$}).
with_content(%r{^exec /usr/bin/aptly api serve -listen=:8080$}).
that_notifies('Service[aptly-api]')
end
describe 'group' do
context 'custom' do
let(:params) { { group: 'yolo' } }

it do
is_expected.to contain_service('aptly-api').
with_ensure('running').
with_enable(true)
end
end

describe 'ensure' do
context 'present (default)' do
let(:params) { {} }

it { is_expected.to contain_service('aptly-api').with_ensure('running') }
end

context 'stopped' do
let(:params) do
{
ensure: 'stopped'
}
it { is_expected.to contain_file('aptly-systemd').with_content(%r{^Group=yolo$}) }
end

it { is_expected.to contain_service('aptly-api').with_ensure('stopped') }
end
end

describe 'user' do
context 'custom' do
let(:params) do
{
user: 'yolo'
}
end

it { is_expected.to contain_file('aptly-upstart').with_content(%r{^setuid yolo$}) }
end
end

describe 'group' do
context 'custom' do
let(:params) do
{
group: 'yolo'
}
end

it { is_expected.to contain_file('aptly-upstart').with_content(%r{^setgid yolo$}) }
end
end
describe 'listen' do
context 'custom' do
let(:params) { { listen: '127.0.0.1:9090' } }

describe 'listen' do
context 'custom' do
let(:params) do
{
listen: '127.0.0.1:9090'
}
it { is_expected.to contain_file('aptly-systemd').with_content(%r{^ExecStart=/usr/bin/aptly api serve -listen=127.0.0.1:9090$}) }
end

it { is_expected.to contain_file('aptly-upstart').with_content(%r{^exec /usr/bin/aptly api serve -listen=127.0.0.1:9090$}) }
end
end

describe 'log' do
context 'none (default)' do
let(:params) { {} }

it { is_expected.to contain_file('aptly-upstart').with_content(%r{^console none$}) }
end

context 'log' do
let(:params) do
{
log: 'log'
}
describe 'enable_cli_and_http' do
context 'false (default)' do
it { is_expected.to contain_file('aptly-systemd').without_content(%r{ -no-lock}) }
end

it { is_expected.to contain_file('aptly-upstart').with_content(%r{^console log$}) }
end
end

describe 'enable_cli_and_http' do
context 'false (default)' do
it { is_expected.to contain_file('aptly-upstart').without_content(%r{ -no-lock}) }
end
context 'true' do
let(:params) { { enable_cli_and_http: true } }

context 'true' do
let(:params) do
{
enable_cli_and_http: true
}
it { is_expected.to contain_file('aptly-systemd').with_content(%r{ -no-lock}) }
end

it { is_expected.to contain_file('aptly-upstart').with_content(%r{ -no-lock}) }
end
end
end
Expand Down
Loading

0 comments on commit 2e1bfb5

Please sign in to comment.