]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/staging/spec/defines/staging_file_spec.rb
add nanliu/staging to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / staging / spec / defines / staging_file_spec.rb
1 require 'spec_helper'
2 describe 'staging::file', :type => :define do
3
4   # forcing a more sane caller_module_name to match real usage.
5   let(:facts) { { :caller_module_name => 'spec',
6                   :osfamily           => 'RedHat',
7                   :staging_http_get   => 'curl' } }
8
9   describe 'when deploying via puppet' do
10     let(:title) { 'sample.tar.gz' }
11     let(:params) { { :source => 'puppet:///modules/staging/sample.tar.gz' } }
12
13     it {
14       should contain_file('/opt/staging')
15       should contain_file('/opt/staging/spec/sample.tar.gz')
16       should_not contain_exec('/opt/staging/spec/sample.tar.gz')
17     }
18   end
19
20   describe 'when deploying via local' do
21     let(:title) { 'sample.tar.gz' }
22     let(:params) { { :source => '/nfs/sample.tar.gz',
23       :target => '/usr/local/sample.tar.gz',
24     } }
25
26     it {
27       should contain_file('/opt/staging')
28       should contain_file('/usr/local/sample.tar.gz')
29       should_not contain_exec('/opt/staging/spec/sample.tar.gz')
30     }
31   end
32
33   describe 'when deploying via http' do
34     let(:title) { 'sample.tar.gz' }
35     let(:params) { { :source => 'http://webserver/sample.tar.gz' } }
36
37     it {
38       should contain_file('/opt/staging')
39       should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
40         :command => 'curl  -f -L -o /opt/staging/spec/sample.tar.gz http://webserver/sample.tar.gz',
41         :path        => '/usr/local/bin:/usr/bin:/bin',
42         :environment => nil,
43         :cwd         => '/opt/staging/spec',
44         :creates     => '/opt/staging/spec/sample.tar.gz',
45         :logoutput   => 'on_failure',
46       })
47     }
48   end
49
50   describe 'when deploying via http with custom curl options' do
51     let(:title) { 'sample.tar.gz' }
52     let(:params) { {
53       :source => 'http://webserver/sample.tar.gz',
54       :curl_option => '-b',
55     } }
56
57     it {
58       should contain_file('/opt/staging')
59       should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
60         :command => 'curl -b -f -L -o /opt/staging/spec/sample.tar.gz http://webserver/sample.tar.gz',
61         :path        => '/usr/local/bin:/usr/bin:/bin',
62         :environment => nil,
63         :cwd         => '/opt/staging/spec',
64         :creates     => '/opt/staging/spec/sample.tar.gz',
65         :logoutput   => 'on_failure',
66       })
67     }
68   end
69
70   describe 'when deploying via http with parameters' do
71     let(:title) { 'sample.tar.gz' }
72     let(:params) { { :source => 'http://webserver/sample.tar.gz',
73       :target    => '/usr/local/sample.tar.gz',
74       :tries     => '10',
75       :try_sleep => '6',
76     } }
77
78     it { should contain_file('/opt/staging')
79       should contain_exec('/usr/local/sample.tar.gz').with( {
80         :command => 'curl  -f -L -o /usr/local/sample.tar.gz http://webserver/sample.tar.gz',
81         :path        => '/usr/local/bin:/usr/bin:/bin',
82         :environment => nil,
83         :cwd         => '/usr/local',
84         :creates     => '/usr/local/sample.tar.gz',
85         :tries       => '10',
86         :try_sleep   => '6',
87       })
88     }
89   end
90
91   describe 'when deploying via https' do
92      let(:title) { 'sample.tar.gz' }
93      let(:params) { { :source => 'https://webserver/sample.tar.gz' } }
94
95      it { should contain_file('/opt/staging') }
96      it { should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
97        :command => 'curl  -f -L -o /opt/staging/spec/sample.tar.gz https://webserver/sample.tar.gz',
98        :path        => '/usr/local/bin:/usr/bin:/bin',
99        :environment => nil,
100        :cwd         => '/opt/staging/spec',
101        :creates     => '/opt/staging/spec/sample.tar.gz',
102        :logoutput   => 'on_failure',
103      }) }
104   end
105
106   describe 'when deploying via https with parameters' do
107     let(:title) { 'sample.tar.gz' }
108     let(:params) { { :source => 'https://webserver/sample.tar.gz',
109       :username => 'puppet',
110       :password => 'puppet',
111     } }
112
113     it {
114       should contain_file('/opt/staging')
115       should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
116         :command => 'curl  -f -L -o /opt/staging/spec/sample.tar.gz -u puppet:puppet https://webserver/sample.tar.gz',
117         :path        => '/usr/local/bin:/usr/bin:/bin',
118         :environment => nil,
119         :cwd         => '/opt/staging/spec',
120         :creates     => '/opt/staging/spec/sample.tar.gz',
121         :logoutput   => 'on_failure',
122       })
123     }
124   end
125
126   describe 'when deploying via ftp' do
127     let(:title) { 'sample.tar.gz' }
128     let(:params) { { :source => 'ftp://webserver/sample.tar.gz' } }
129
130     it {
131       should contain_file('/opt/staging')
132       should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
133         :command => 'curl  -o /opt/staging/spec/sample.tar.gz ftp://webserver/sample.tar.gz',
134         :path        => '/usr/local/bin:/usr/bin:/bin',
135         :environment => nil,
136         :cwd         => '/opt/staging/spec',
137         :creates     => '/opt/staging/spec/sample.tar.gz',
138         :logoutput   => 'on_failure',
139       })
140     }
141   end
142
143   describe 'when deploying via ftp with parameters' do
144     let(:title) { 'sample.tar.gz' }
145     let(:params) { { :source => 'ftp://webserver/sample.tar.gz',
146       :username => 'puppet',
147       :password => 'puppet',
148     } }
149
150     it {
151       should contain_file('/opt/staging')
152       should contain_exec('/opt/staging/spec/sample.tar.gz').with( {
153         :command => 'curl  -o /opt/staging/spec/sample.tar.gz -u puppet:puppet ftp://webserver/sample.tar.gz',
154         :path        => '/usr/local/bin:/usr/bin:/bin',
155         :environment => nil,
156         :cwd         => '/opt/staging/spec',
157         :creates     => '/opt/staging/spec/sample.tar.gz',
158         :logoutput   => 'on_failure',
159       })
160     }
161   end
162
163 end