|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe 'perlbrew::perl', :type => :define do
|
4 |
| - let(:title) { 'perl-5.18.2' } |
5 |
| - let(:params) {{ :target => 'foo' }} |
6 |
| - let(:pre_condition) { "perlbrew { 'foo': install_root => '/dne' }" } |
| 4 | + let(:facts) {{ :processorcount => 42 }} |
7 | 5 |
|
8 |
| - context 'default params' do |
9 |
| - it { should contain_exec('foo_install_perl-5.18.2').with( |
10 |
| - :command => 'perlbrew install perl-5.18.2', |
| 6 | + let(:install_root) { '/dne' } |
| 7 | + let(:version) { 'perl-5.18.2' } |
| 8 | + let(:target) { 'foo' } |
| 9 | + let(:flags) { "--notest -j #{facts[:processorcount]}" } |
| 10 | + |
| 11 | + let(:title) { version } |
| 12 | + let(:params) {{ :target => target }} |
| 13 | + let(:pre_condition) { "perlbrew { '#{target}': install_root => '#{install_root}' }" } |
| 14 | + |
| 15 | + let(:perlbrew_env) { [ |
| 16 | + "HOME=#{install_root}", |
| 17 | + 'PERLBREW_VERSION=0.71', |
| 18 | + "PERLBREW_PERL=#{version}", |
| 19 | + 'PERLBREW_BASHRC_VERSION=0.71', |
| 20 | + "PERLBREW_ROOT=#{install_root}/perl5/perlbrew", |
| 21 | + "PERLBREW_HOME=#{install_root}/.perlbrew", |
| 22 | + "PERLBREW_MANPATH=#{install_root}/perl5/perlbrew/perls/#{version}/man", |
| 23 | + "PERLBREW_PATH=#{install_root}/perl5/perlbrew/bin:#{install_root}/perl5/perlbrew/perls/#{version}/bin", |
| 24 | + ]} |
| 25 | + let(:perlbrew_path) {[ |
| 26 | + "#{install_root}/perl5/perlbrew/bin", |
| 27 | + "#{install_root}/perl5/perlbrew/perls/#{version}/bin", |
| 28 | + '/bin', |
| 29 | + '/usr/bin', |
| 30 | + ]} |
| 31 | + |
| 32 | + shared_examples 'guts' do |
| 33 | + it { should contain_perlbrew__perl(title).that_requires("Perlbrew[#{target}]") } |
| 34 | + |
| 35 | + it { should contain_exec("#{target}_install_#{version}").with( |
| 36 | + :command => "perlbrew install #{flags} #{version}", |
| 37 | + :path => perlbrew_path, |
| 38 | + :environment => perlbrew_env, |
| 39 | + :cwd => '/dne', |
| 40 | + :user => nil, |
| 41 | + :group => nil, |
| 42 | + :logoutput => true, |
| 43 | + :creates => "/dne/perl5/perlbrew/perls/#{version}", |
| 44 | + :timeout => 3600 |
| 45 | + ) |
| 46 | + } |
| 47 | + |
| 48 | + it { should contain_exec("#{target}_install-cpanm-#{version}").with( |
| 49 | + :command => 'perlbrew install-cpanm', |
| 50 | + :path => perlbrew_path, |
| 51 | + :environment => perlbrew_env, |
11 | 52 | :cwd => '/dne',
|
12 | 53 | :user => nil,
|
13 | 54 | :group => nil,
|
14 | 55 | :logoutput => true,
|
15 |
| - :creates => '/dne/perl5/perlbrew/perls/perl-5.18.2' |
| 56 | + :unless => 'which cpanm' |
16 | 57 | )
|
17 | 58 | }
|
18 |
| - it { should contain_exec('foo_switch_perl-5.18.2').with( |
19 |
| - :command => 'perlbrew switch perl-5.18.2', |
| 59 | + it { should contain_exec("#{target}_install-cpanm-#{version}").that_requires("Exec[#{target}_install_#{version}]") } |
| 60 | + |
| 61 | + it { should contain_exec("#{target}_switch_#{version}").with( |
| 62 | + :command => "perlbrew switch #{version}", |
| 63 | + :path => perlbrew_path, |
| 64 | + :environment => perlbrew_env, |
20 | 65 | :cwd => '/dne',
|
21 | 66 | :user => nil,
|
22 | 67 | :group => nil,
|
23 | 68 | :logoutput => true,
|
24 |
| - :unless => "grep PERLBREW_PERL=\\\"perl-5.18.2\\\" /dne/.perlbrew/init" |
| 69 | + :unless => "grep PERLBREW_PERL=\\\"#{version}\\\" /dne/.perlbrew/init" |
25 | 70 | )
|
26 | 71 | }
|
27 |
| - end |
| 72 | + it { should contain_exec("#{target}_switch_#{version}").that_requires("Exec[#{target}_install-cpanm-#{version}]") } |
| 73 | + end # guts |
| 74 | + |
| 75 | + context 'default params' do |
| 76 | + it_behaves_like 'guts' |
| 77 | + end # default params |
| 78 | + |
| 79 | + context 'target =>' do |
| 80 | + context 'bar' do |
| 81 | + let(:target) { 'foo' } |
| 82 | + before { params[:target] = target } |
| 83 | + |
| 84 | + it_behaves_like 'guts' |
| 85 | + end |
| 86 | + |
| 87 | + context '[]' do |
| 88 | + let(:params) {{ :target => [] }} |
| 89 | + |
| 90 | + it 'should fail' do |
| 91 | + expect { should }.to raise_error(Puppet::Error, /is not a string/) |
| 92 | + end |
| 93 | + end |
| 94 | + end # target => |
| 95 | + |
| 96 | + context 'version =>' do |
| 97 | + context '2.18.5-lrep' do |
| 98 | + let(:version) { '2.18.5-lrep' } |
| 99 | + before { params[:version] = version } |
| 100 | + |
| 101 | + it_behaves_like 'guts' |
| 102 | + end |
| 103 | + |
| 104 | + context '[]' do |
| 105 | + before { params[:version] = [] } |
| 106 | + |
| 107 | + it 'should fail' do |
| 108 | + expect { should }.to raise_error(Puppet::Error, /is not a string/) |
| 109 | + end |
| 110 | + end |
| 111 | + end # version => |
| 112 | + |
| 113 | + context 'flags =>' do |
| 114 | + context '--ponies' do |
| 115 | + let(:flags) { '--ponies' } |
| 116 | + before { params[:flags] = flags } |
| 117 | + |
| 118 | + it_behaves_like 'guts' |
| 119 | + end |
| 120 | + |
| 121 | + context '[]' do |
| 122 | + before { params[:flags] = [] } |
| 123 | + |
| 124 | + it 'should fail' do |
| 125 | + expect { should }.to raise_error(Puppet::Error, /is not a string/) |
| 126 | + end |
| 127 | + end |
| 128 | + end # flags => |
28 | 129 | end
|
0 commit comments