Skip to content

Commit

Permalink
Update cli project config and update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris29 committed Jan 15, 2024
1 parent bd34516 commit 8692e3c
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 56 deletions.
1 change: 1 addition & 0 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

$projects.each |$_name, $_attr| {
rundeck::config::project { $_name:
* => $_attr,
require => Exec['Check rundeck cli connection'],
}
}
Expand Down
119 changes: 105 additions & 14 deletions spec/classes/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,124 @@
end

context 'with default parameters' do
it { is_expected.not_to compile }
end
it { is_expected.to compile }

context 'with manage_repo => true' do
let(:params) do
{
'manage_repo' => true,
}
end
it { is_expected.to contain_package('jq').with(ensure: 'present') }

case facts[:os]['family']
when 'RedHat'
it do
it {
is_expected.to contain_yumrepo('rundeck').with(
baseurl: 'https://packages.rundeck.com/pagerduty/rundeck/rpm_any/rpm_any/$basearch',
repo_gpgcheck: 1,
gpgcheck: 0,
enabled: 1,
gpgkey: 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey'
).that_comes_before('Package[rundeck]')
end
).that_comes_before('Package[rundeck-cli]')
}
when 'Debian'
it { is_expected.to contain_apt__source('rundeck').with_location('https://packages.rundeck.com/pagerduty/rundeck/any') }
it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') }
it { is_expected.to contain_package('rundeck').that_notifies('Class[rundeck::service]') }
it {
is_expected.to contain_apt__source('rundeck').with(
location: 'https://packages.rundeck.com/pagerduty/rundeck/any',
release: 'any',
repos: 'main',
key: {
'name' => 'rundeck',
'source' => 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey',
}
).that_comes_before('Package[rundeck-cli]')
}

it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck-cli]') }
it { is_expected.to contain_package('rundeck-cli').with(ensure: 'installed') }
it { is_expected.to contain_file('/usr/local/bin/rd_project_diff.sh').with(ensure: 'file', mode: '0755') }

it {
is_expected.to contain_exec('Check rundeck cli connection').with(
command: 'rd system info',
path: ['/bin', '/usr/bin', '/usr/local/bin'],
environment: [
'RD_FORMAT=json',
'RD_URL=http://localhost:4440',
'RD_BYPASS_URL=http://localhost:4440',
'RD_USER=admin',
'RD_PASSWORD=admin',
],
tries: 60,
try_sleep: 5,
unless: 'rd system info &> /dev/null'
).that_requires('Package[rundeck-cli]')
}
end
end

context 'with different urls and token auth' do
let(:params) do
{
url: 'http://rundeck01.example.com',
bypass_url: 'http://rundeck.example.com',
token: 'very_secure'
}
end

it {
is_expected.to contain_exec('Check rundeck cli connection').with(
environment: [
'RD_FORMAT=json',
'RD_URL=http://rundeck01.example.com',
'RD_BYPASS_URL=http://rundeck.example.com',
'RD_TOKEN=very_secure',
]
)
}
end

context 'with projects config' do
let(:params) do
{
projects: {
'MyProject' => {
'update_method' => 'set',
'config' => {
'project.description' => 'This is My rundeck project',
'project.disable.executions' => 'false',
},
},
'TestProject' => {
'config' => {
'project.description' => 'This is a rundeck test project',
'project.disable.schedule' => 'false',
},
},
},
}
end

it {
is_expected.to contain_rundeck__config__project('MyProject').with(
update_method: 'set',
config: {
'project.description' => 'This is My rundeck project',
'project.disable.executions' => 'false',
}
)
}

it { is_expected.to contain_exec('Create rundeck project: MyProject') }
it { is_expected.to contain_exec('Manage rundeck project: MyProject') }

it {
is_expected.to contain_rundeck__config__project('TestProject').with(
config: {
'project.description' => 'This is a rundeck test project',
'project.disable.schedule' => 'false',
}
)
}

it { is_expected.to contain_exec('Create rundeck project: TestProject') }
it { is_expected.to contain_exec('Manage rundeck project: TestProject') }
end
end
end
end
20 changes: 10 additions & 10 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
facts
end

context 'without any parameters test rundeck::config' do
it { is_expected.to contain_file('/var/lib/rundeck').with('ensure' => 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/libext').with('ensure' => 'directory') }
it { is_expected.to contain_file('/etc/rundeck').with('ensure' => 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var').with('ensure' => 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var/tmp').with('ensure' => 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var/logs').with('ensure' => 'directory') }
context 'with default parameters test rundeck::config' do
it { is_expected.to contain_file('/var/lib/rundeck').with(ensure: 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/libext').with(ensure: 'directory') }
it { is_expected.to contain_file('/etc/rundeck').with(ensure: 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var').with(ensure: 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var/tmp').with(ensure: 'directory') }
it { is_expected.to contain_file('/var/lib/rundeck/var/logs').with(ensure: 'directory') }

it { is_expected.to contain_file('/var/log/rundeck').with('ensure' => 'directory') }
it { is_expected.to contain_file('/var/log/rundeck').with(ensure: 'directory') }

it { is_expected.to contain_file('/etc/rundeck/log4j2.properties') }

Expand Down Expand Up @@ -50,8 +50,8 @@
it { is_expected.to contain_class('rundeck::config::jaas_auth') }
it { is_expected.to contain_class('rundeck::config::framework') }

it { is_expected.to contain_file('/etc/rundeck/project.properties').with('ensure' => 'absent') }
it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with('ensure' => 'file') }
it { is_expected.to contain_file('/etc/rundeck/project.properties').with(ensure: 'absent') }
it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with(ensure: 'file') }

it 'generates valid content for rundeck-config.properties' do
content = catalogue.resource('file', '/etc/rundeck/rundeck-config.properties')[:content]
Expand Down
48 changes: 23 additions & 25 deletions spec/classes/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@
facts
end

context 'without any parameters test rundeck::install' do
let(:params) { {} }

context 'with default parameters test rundeck::install' do
it { is_expected.not_to contain_group('rundeck') }
it { is_expected.not_to contain_user('rundeck') }

case facts[:os]['family']
when 'RedHat'
it do
it {
is_expected.to contain_yumrepo('rundeck').with(
baseurl: 'https://packages.rundeck.com/pagerduty/rundeck/rpm_any/rpm_any/$basearch',
repo_gpgcheck: 1,
gpgcheck: 0,
enabled: 1,
gpgkey: 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey'
).that_comes_before('Package[rundeck]')
end
}
when 'Debian'
it { is_expected.to contain_apt__source('rundeck').with_location('https://packages.rundeck.com/pagerduty/rundeck/any') }
it {
is_expected.to contain_apt__source('rundeck').with(
location: 'https://packages.rundeck.com/pagerduty/rundeck/any',
release: 'any',
repos: 'main',
key: {
'name' => 'rundeck',
'source' => 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey',
}
).that_comes_before('Package[rundeck]')
}

it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') }
it { is_expected.to contain_package('rundeck').that_notifies('Class[rundeck::service]') }
it { is_expected.to contain_package('rundeck').with(ensure: 'installed') }
end
end

Expand All @@ -42,13 +52,13 @@
}
end

it { is_expected.to contain_group('A1234').with('ensure' => 'present') }
it { is_expected.to contain_group('A1234').with(ensure: 'present') }

it { is_expected.to contain_group('rundeck').with('ensure' => 'absent') }
it { is_expected.to contain_group('rundeck').with(ensure: 'absent') }

it { is_expected.to contain_user('A1234').with('ensure' => 'present') }
it { is_expected.to contain_user('A1234').with(ensure: 'present') }

it { is_expected.to contain_user('rundeck').with('ensure' => 'absent') }
it { is_expected.to contain_user('rundeck').with(ensure: 'absent') }
end

context 'different user and group with ids' do
Expand All @@ -63,20 +73,8 @@
}
end

it do
is_expected.to contain_group('A1234').with(
'ensure' => 'present',
'gid' => 10_000
)
end

it do
is_expected.to contain_user('A1234').with(
'ensure' => 'present',
'gid' => '10000',
'uid' => '10000'
)
end
it { is_expected.to contain_group('A1234').with(ensure: 'present', gid: 10_000) }
it { is_expected.to contain_user('A1234').with(ensure: 'present', gid: 10_000, uid: 10_000) }
end
end
end
Expand Down
15 changes: 12 additions & 3 deletions spec/classes/rundeck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
facts
end

context 'without any parameters test rundeck' do
let(:params) { {} }

context 'with default parameters test rundeck' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('rundeck::install').that_comes_before('Class[rundeck::config]') }
it { is_expected.to contain_class('rundeck::config').that_notifies('Class[rundeck::service]') }
Expand Down Expand Up @@ -59,6 +57,17 @@
expect(content).to include('rundeck.server.uuid = ac7c2cbd-14fa-5ba3-b3f2-d436e9b8a3b0')
end
end

context 'with manage_cli => false' do
let(:params) do
{
manage_cli: false
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_class('rundeck::cli') }
end
end
end
end
6 changes: 2 additions & 4 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
facts
end

context 'without any parameters test rundeck::service' do
let(:params) { {} }

it { is_expected.to contain_service('rundeckd') }
context 'with default parameters test rundeck::service' do
it { is_expected.to contain_service('rundeckd').with(ensure: 'running') }
end
end
end
Expand Down

0 comments on commit 8692e3c

Please sign in to comment.