diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb deleted file mode 100644 index f002bd5..0000000 --- a/spec/classes/config_spec.rb +++ /dev/null @@ -1,147 +0,0 @@ -require 'spec_helper' - -describe 'cpan::config' do - on_supported_os.each do |os, os_facts| - context "On #{os}" do - let(:facts) { os_facts } - - context 'With default ::cpan parameters' do - let(:pre_condition) do - [ - 'include cpan', - ] - end - - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_owner('root') } - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_group('root') } - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_mode('0644') } - when 'RedHat' - case os_facts[:os]['release']['major'] - when '5' - it { - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_mode('0644') - } - when '6' - it { - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') - } - when '7' - it { - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'http_proxy' => q\[\],$}) - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'ftp_proxy' => q\[\],$}) - } - it 'has empty urlist' do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' ],', - ]) - end - when '8' - it { - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_mode('0644') - } - end - end - end - context 'With custom ::cpan parameters' do - case os_facts[:osfamily] - when 'RedHat' - case os_facts[:os]['release']['major'] - when '7' - context 'with proxies set' do - let(:pre_condition) do - [ - 'class { "cpan": - ftp_proxy => "http://your_ftp_proxy.com", - http_proxy => "http://your_http_proxy.com", - } - ', - ] - end - - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'ftp_proxy' => q\[http://your_ftp_proxy\.com\],$}) } - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'http_proxy' => q\[http://your_http_proxy\.com\],$}) } - end - context 'with custom param set' do - describe 'string' do - let(:pre_condition) do - [ - 'class { "cpan": - config_hash => { "foo" => "bar" } - }', - ] - end - - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'foo' => q\[bar],$}) } - end - describe 'array' do - let(:pre_condition) do - [ - 'class {"cpan": - config_hash => { "foo" => ["baz","bar"] } - }', - ] - end - - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'foo' => [", - ' q[baz],', - ' q[bar]', - ]) - end - end - end - context 'with urllist set' do - describe 'single url' do - let(:pre_condition) do - 'class { "cpan": - urllist => ["http://httpupdate3.cpanel.net/CPAN/"], - }' - end - - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' q[http://httpupdate3.cpanel.net/CPAN/]', - ' ],', - ]) - end - end - describe 'two urls' do - let(:pre_condition) do - 'class { "::cpan": - urllist => [ - "http://httpupdate3.cpanel.net/CPAN/", - "ftp://cpan.cse.msu.edu/" - ], - }' - end - - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' q[http://httpupdate3.cpanel.net/CPAN/],', - ' q[ftp://cpan.cse.msu.edu/]', - ' ],', - ]) - end - end - end - end - end - end - end - end -end diff --git a/spec/classes/cpan_spec.rb b/spec/classes/cpan_spec.rb deleted file mode 100644 index 6cdd07b..0000000 --- a/spec/classes/cpan_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -describe 'cpan' do - on_supported_os.each do |os, os_facts| - context "On #{os}" do - let(:facts) { os_facts } - - it { is_expected.to contain_class('cpan::install') } - it { is_expected.to contain_class('cpan::config') } - - describe 'cpan::install' do - let(:params) { { package_ensure: 'present', manage_package: true, local_lib: false } } - - it { is_expected.to contain_package('gcc').with(ensure: 'present') } - it { is_expected.to contain_package('make').with(ensure: 'present') } - - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('perl').with(ensure: 'present') } - when 'RedHat' - it { is_expected.to contain_package('perl-CPAN').with(ensure: 'present') } - end - - describe 'should allow package ensure to be overridden' do - let(:params) { { package_ensure: 'latest', manage_package: true } } - - it { is_expected.to contain_package('gcc').with_ensure('latest') } - it { is_expected.to contain_package('make').with_ensure('latest') } - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('perl').with(ensure: 'latest') } - when 'RedHat' - it { is_expected.to contain_package('perl-CPAN').with(ensure: 'latest') } - end - end - end - end - end -end diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb deleted file mode 100644 index 243e04e..0000000 --- a/spec/classes/install_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper' - -describe 'cpan::install' do - on_supported_os.each do |os, os_facts| - context "On #{os}" do - let(:facts) { os_facts } - - describe 'package_ensure and manage_package' do - let(:pre_condition) do - [ - 'class { "cpan": - package_ensure => "present", - manage_package => true, - local_lib => false, - } - ', - ] - end - - it { is_expected.to contain_package('gcc').with(ensure: 'present') } - it { is_expected.to contain_package('make').with(ensure: 'present') } - - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('perl').with(ensure: 'present') } - when 'RedHat' - it { is_expected.to contain_package('perl-CPAN').with(ensure: 'present') } - end - end - describe 'should allow package ensure to be overridden' do - let(:pre_condition) do - [ - 'class { "cpan": - package_ensure => "latest", - manage_package => true, - } - ', - ] - end - - it { is_expected.to contain_package('gcc').with_ensure('latest') } - it { is_expected.to contain_package('make').with_ensure('latest') } - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_package('perl').with(ensure: 'latest') } - when 'RedHat' - it { is_expected.to contain_package('perl-CPAN').with(ensure: 'latest') } - end - end - end - end -end diff --git a/spec/types/cpan_spec.rb b/spec/types/cpan_spec.rb index 1324828..aa1f7a4 100644 --- a/spec/types/cpan_spec.rb +++ b/spec/types/cpan_spec.rb @@ -5,71 +5,12 @@ describe 'cpan' do let(:title) { 'baz' } - describe 'valid type' do - it { is_expected.to be_valid_type } - end - describe 'ensure' do - [:present, :absent, :installed, :latest].each do |value| - it "accepts #{value} as a value" do - is_expected.to be_valid_type.with_set_attributes(ensure: value) - end - end - it 'rejects other values' do - expect { described_type.new(name: 'test', ensure: 'foo') }.to raise_error(Puppet::Error) - end - end - - describe 'name' do - it 'is the namevar' do - expect(described_type.key_attributes).to eq([:name]) - end - end - - describe 'local_lib' do - it 'accepts an absolute path' do - is_expected.to be_valid_type.with_set_attributes(local_lib: '/path/to/file') - end - it 'accepts false' do - is_expected.to be_valid_type.with_set_attributes(local_lib: false) - end - end - describe 'force' do - [true, false, 'true', 'false', 'no', 'yes'].each do |value| - it "accepts #{value}" do - is_expected.to be_valid_type.with_set_attributes(force: value) - end - end - it 'rejects other values' do - # for some reason expect { be_valid_type.with_set_attributes({:force => 'nope'})}.to raise_error doesn't raise - # expect {be_valid_type.with_set_attributes({:force => 'nope'})}.to raise_error(Puppet::ResourceError) + it 'rejects other values (rspec)' do expect { described_type.new(name: 'test', force: 'nope') }.to raise_error(Puppet::Error) end - it 'defaults to false' do - expect(described_type.new(name: 'test')[:force]).to eq(false) - end - it 'munges \'false\' to false' do - expect(described_type.new(name: 'test', force: 'false')[:force]).to eq(false) - end - it 'munges \'true\' to true' do - expect(described_type.new(name: 'test', force: 'true')[:force]).to eq(true) - end - end - - describe 'umask' do - describe 'valid values' do - ['0022', '022', '0027', '027'].each do |value| - it "accepts #{value}" do - is_expected.to be_valid_type.with_set_attributes(umask: value) - end - end - end - describe 'invalid values' do - [true, false, 220, '0', '888', 'invalid'].each do |value| - it "rejects #{value}" do - expect { described_type.new(name: 'test', umask: value) }.to raise_error(Puppet::Error) - end - end + it 'rejects other values (be_valid_type)' do + expect { be_valid_type.with_set_attributes(force: 'nope') }.to raise_error(Puppet::Error) end end end diff --git a/spec/types/cpan_spec_minimal.rb b/spec/types/cpan_spec_minimal.rb deleted file mode 100644 index 9630405..0000000 --- a/spec/types/cpan_spec_minimal.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -described_type = Puppet::Type.type(:cpan) - -describe 'cpan' do - let(:title) { 'baz' } - - describe 'force' do - it 'rejects other values (rspec)' do - expect { described_type.new(name: 'test', force: 'nope') }.to raise_error(Puppet::Error) - end - it 'rejects other values (be_valid_type)' do - expect {be_valid_type.with_set_attributes({:force => 'nope'})}.to raise_error(Puppet::Error) - end - end -end