|
| 1 | +require 'spec_helper' |
| 2 | +require 'yaml' |
| 3 | +facts_yaml = File.dirname(__FILE__) + '/../fixtures/facts/spec.yaml' |
| 4 | +facts = YAML.load_file(facts_yaml) |
| 5 | + |
| 6 | +describe 'profile::ssh::openssh', :type => :class do |
| 7 | + let(:facts) { facts } |
| 8 | + |
| 9 | + on_supported_os.each do |os, facts| |
| 10 | + context "on #{os}" do |
| 11 | + let (:facts) do |
| 12 | + facts.merge(super()) |
| 13 | + end |
| 14 | + |
| 15 | + # it { pp catalogue.resources } # Uncomment to dump the catalogue |
| 16 | + |
| 17 | + it { is_expected.to compile.with_all_deps } |
| 18 | + it { is_expected.to contain_class('profile::ssh::openssh') } |
| 19 | + |
| 20 | + context 'with defaults values' do |
| 21 | + it { is_expected.not_to contain_tp__conf('openssh') } |
| 22 | + |
| 23 | + it { is_expected.to contain_tp__dir('openssh').with( |
| 24 | + 'ensure' => 'present', |
| 25 | + 'source' => nil |
| 26 | + ) } |
| 27 | + |
| 28 | + it { is_expected.to contain_tp__install('openssh').with( |
| 29 | + 'ensure' => 'present' |
| 30 | + ) } |
| 31 | + end |
| 32 | + |
| 33 | + context 'with :ensure parameter specified' do |
| 34 | + let :default_params do |
| 35 | + { |
| 36 | + :config_dir_source => 'test_config_dir_source', |
| 37 | + :config_file_template => '/dev/null', |
| 38 | + } |
| 39 | + end |
| 40 | + |
| 41 | + describe 'with parameter: ensure set to absent' do |
| 42 | + let :params do |
| 43 | + default_params.merge({:ensure => 'absent'}) |
| 44 | + end |
| 45 | + |
| 46 | + it { is_expected.to contain_tp__install('openssh').with( |
| 47 | + 'ensure' => 'absent' |
| 48 | + ) } |
| 49 | + |
| 50 | + it { is_expected.to contain_tp__dir('openssh').with( |
| 51 | + 'ensure' => 'absent', |
| 52 | + 'source' => 'test_config_dir_source' |
| 53 | + ) } |
| 54 | + |
| 55 | + it { is_expected.to contain_tp__conf('openssh').with( |
| 56 | + 'ensure' => 'absent', |
| 57 | + 'template' => '/dev/null', |
| 58 | + 'options_hash' => {'option1' => 'option1_value', |
| 59 | + 'option2' => 'option2_value'} |
| 60 | + ) } |
| 61 | + end |
| 62 | + |
| 63 | + describe 'with parameter :ensure set to present' do |
| 64 | + let :params do |
| 65 | + default_params.merge({:ensure => 'present'}) |
| 66 | + end |
| 67 | + |
| 68 | + it { is_expected.to contain_tp__install('openssh').with( |
| 69 | + 'ensure' => 'present' |
| 70 | + ) } |
| 71 | + |
| 72 | + it { is_expected.to contain_tp__conf('openssh').with( |
| 73 | + 'ensure' => 'present', |
| 74 | + 'template' => '/dev/null', |
| 75 | + 'options_hash' => {'option1' => 'option1_value', |
| 76 | + 'option2' => 'option2_value'} |
| 77 | + ) } |
| 78 | + |
| 79 | + it { is_expected.to contain_tp__dir('openssh').with( |
| 80 | + 'ensure' => 'present', |
| 81 | + 'source' => 'test_config_dir_source' |
| 82 | + ) } |
| 83 | + end |
| 84 | + |
| 85 | + end |
| 86 | + |
| 87 | + context 'with invalid parameter values' do |
| 88 | + describe 'with :ensure not equal to "present" or "absent"' do |
| 89 | + let :params do |
| 90 | + { |
| 91 | + :ensure => 'invalid' |
| 92 | + } |
| 93 | + end |
| 94 | + it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error.* got \'invalid\'.*/) } |
| 95 | + end |
| 96 | + |
| 97 | + describe 'with :config_dir_source set to empty string' do |
| 98 | + let :params do |
| 99 | + { |
| 100 | + :ensure => 'present', |
| 101 | + :config_dir_source => '' |
| 102 | + } |
| 103 | + end |
| 104 | + it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error:.*/) } |
| 105 | + end |
| 106 | + |
| 107 | + describe 'with :config_dir_source not a string' do |
| 108 | + let :params do |
| 109 | + { |
| 110 | + :ensure => 'present', |
| 111 | + :config_dir_source => 1 |
| 112 | + } |
| 113 | + end |
| 114 | + it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error:.*/) } |
| 115 | + end |
| 116 | + |
| 117 | + end |
| 118 | + end |
| 119 | + end |
| 120 | +end |
| 121 | + |
| 122 | + |
0 commit comments