Skip to content

Commit

Permalink
Added tests for main tp class
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Aug 29, 2017
1 parent dad9b04 commit 539010f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,3 +8,6 @@
* More Puppet 4 language constructs
* Removed pick_undef and tp_pick functions. Use stdlib pick_default
* Removed tp::concat define
### Added:
* Refactored spec tests. Now is possible to test any tp define on any os on any app
* Added tests for tp::test, tp::uninstall, tp::stdmod
2 changes: 2 additions & 0 deletions manifests/init.pp
Expand Up @@ -41,6 +41,8 @@
}

file { $tp_path:
ensure => present,
path => $tp_path,
owner => $tp_owner,
group => $tp_group,
mode => '0755',
Expand Down
40 changes: 40 additions & 0 deletions spec/classes/tp_spec.rb
@@ -0,0 +1,40 @@
require 'spec_helper'

describe 'tp' do
on_supported_os(facterversion: '2.4').each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'with default params' do
it { is_expected.to compile }
it { should have_file_resource_count(4) }
it { should have_resource_count(4) }
end

context 'with custom tp_dir => /opt/tp, tp_owner =al, tp_group => al, tp_path => /usr/bin/tp' do
let(:params) do {
'tp_dir' => '/opt/tp',
'tp_owner' => 'al',
'tp_group' => 'al',
'tp_path' => '/usr/bin/tp',
} end

dir_params = {
'ensure' => 'directory',
'mode' => '0755',
'owner' => 'al',
'group' => 'al',
}
file_params = {
'ensure' => 'present',
'mode' => '0755',
'owner' => 'al',
'group' => 'al',
'path' => '/usr/bin/tp',
}
it { is_expected.to contain_file('/opt/tp').only_with(dir_params) }
it { is_expected.to contain_file('/usr/bin/tp').with(file_params) }
end
end
end
end
22 changes: 0 additions & 22 deletions spec/defines/tp_repo_spec.rb
Expand Up @@ -10,34 +10,12 @@
apps.each do | app |
appdata=YAML.safe_load(File.read(File.join(File.dirname(__FILE__), "../tpdata/#{os}/#{app}")))

# Default params
default_package_params = {
'ensure' => 'present',
}

# Resource counts with normal tp::repo
total_count = 1
package_count = 0
service_count = 0
exec_count = 0
file_count = 0
has_repo = false
has_service = false

# Added resources when repos are managed
if appdata['repo_url'] or appdata['yum_mirrorlist'] or appdata['repo_package_url']
has_repo = true
repo_params = {
'enabled' => true,
'before' => "Package[#{appdata['package_name']}]",
'data_module' => 'tinydata',
'settings_hash' => {},
'description' => "#{app} repository",
'include_src' => false,
'debug' => false,
'debug_dir' => '/tmp',
}
end

# Increment package count if repo_package_url and repo_package_name are present
if appdata['repo_package_url'] and appdata['repo_package_name']
Expand Down

0 comments on commit 539010f

Please sign in to comment.