poise-languages 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseLanguages::Scl::Mixin do
20
+ resource(:poise_test)
21
+ provider(:poise_test) do
22
+ include described_class
23
+ end
24
+
25
+ describe '#install_scl_package' do
26
+ provider(:poise_test) do
27
+ include Poise
28
+ include described_class
29
+ def scl_package
30
+ {name: 'python34', url: 'http://something.rpm'}
31
+ end
32
+ def action_run
33
+ install_scl_package
34
+ end
35
+ end
36
+ recipe do
37
+ poise_test 'test'
38
+ end
39
+
40
+ it { is_expected.to install_poise_languages_scl('python34').with(parent: chef_run.poise_test('test'), url: 'http://something.rpm') }
41
+ end # /describe #install_scl_package
42
+
43
+ describe '#uninstall_scl_package' do
44
+ provider(:poise_test) do
45
+ include Poise
46
+ include described_class
47
+ def scl_package
48
+ {name: 'python34', url: 'http://something.rpm'}
49
+ end
50
+ def action_run
51
+ uninstall_scl_package
52
+ end
53
+ end
54
+ recipe do
55
+ poise_test 'test'
56
+ end
57
+
58
+ it { is_expected.to uninstall_poise_languages_scl('python34').with(parent: chef_run.poise_test('test'), url: 'http://something.rpm') }
59
+ end # /describe #uninstall_scl_package
60
+
61
+ describe '#scl_package' do
62
+ let(:package) { nil }
63
+ recipe(subject: false) do
64
+ poise_test 'test'
65
+ end
66
+ subject { chef_run.poise_test('test').provider_for_action(:run).send(:scl_package) }
67
+ before do
68
+ allow_any_instance_of(provider(:poise_test)).to receive(:options).and_return({})
69
+ allow(provider(:poise_test)).to receive(:find_scl_package).and_return(package)
70
+ end
71
+
72
+ context 'with a valid package' do
73
+ let(:package) { {name: 'python34'} }
74
+ it { is_expected.to eq(package) }
75
+ end # /context with a valid package
76
+
77
+ context 'without a valid package' do
78
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
79
+ end # /context without a valid package
80
+ end # /describe #scl_package
81
+
82
+ describe '#scl_folder' do
83
+ let(:test_provider) { provider(:poise_test).new(nil, nil) }
84
+ subject { test_provider.send(:scl_folder) }
85
+ before do
86
+ allow(test_provider).to receive(:scl_package).and_return({name: 'python34'})
87
+ end
88
+
89
+ it { is_expected.to eq '/opt/rh/python34' }
90
+ end # /describe #scl_folder
91
+
92
+ describe '#scl_environment' do
93
+ let(:test_provider) { provider(:poise_test).new(nil, nil) }
94
+ subject { test_provider.send(:scl_environment) }
95
+ before do
96
+ allow(test_provider).to receive(:scl_package).and_return({name: 'python34'})
97
+ end
98
+
99
+ it do
100
+ expect(test_provider).to receive(:parse_enable_file).with('/opt/rh/python34/enable')
101
+ subject
102
+ end
103
+ end # /describe #scl_environment
104
+
105
+ describe '#parse_enable_file' do
106
+ let(:content) { '' }
107
+ before do
108
+ allow(File).to receive(:exist?).with('/test/enable').and_return(true)
109
+ allow(IO).to receive(:readlines).with('/test/enable').and_return(content.split(/\n/))
110
+ end
111
+ subject { provider(:poise_test).new(nil, nil).send(:parse_enable_file, '/test/enable') }
112
+
113
+ context 'with an empty file' do
114
+ it { is_expected.to eq({}) }
115
+ end # /context with an empty file
116
+
117
+ context 'with valid data' do
118
+ # $ cat /opt/rh/python33/enable
119
+ let(:content) { <<-EOH }
120
+ export PATH=/opt/rh/python33/root/usr/bin${PATH:+:${PATH}}
121
+ export LD_LIBRARY_PATH=/opt/rh/python33/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
122
+ export MANPATH=/opt/rh/python33/root/usr/share/man:${MANPATH}
123
+ # For systemtap
124
+ export XDG_DATA_DIRS=/opt/rh/python33/root/usr/share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}
125
+ # For pkg-config
126
+ export PKG_CONFIG_PATH=/opt/rh/python33/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
127
+ EOH
128
+ it do
129
+ is_expected.to eq({
130
+ 'PATH' => "/opt/rh/python33/root/usr/bin#{ENV['PATH'] ? ':' + ENV['PATH'] : ''}",
131
+ 'LD_LIBRARY_PATH' => "/opt/rh/python33/root/usr/lib64#{ENV['LD_LIBRARY_PATH'] ? ':' + ENV['LD_LIBRARY_PATH'] : ''}",
132
+ 'MANPATH' => "/opt/rh/python33/root/usr/share/man:#{ENV['MANPATH']}",
133
+ 'XDG_DATA_DIRS' => "/opt/rh/python33/root/usr/share#{ENV['XDG_DATA_DIRS'] ? ':' + ENV['XDG_DATA_DIRS'] : ''}",
134
+ 'PKG_CONFIG_PATH' => "/opt/rh/python33/root/usr/lib64/pkgconfig#{ENV['PKG_CONFIG_PATH'] ? ':' + ENV['PKG_CONFIG_PATH'] : ''}",
135
+ })
136
+ end
137
+ end # /context with valid data
138
+
139
+ context 'with a non-existent file' do
140
+ before do
141
+ allow(File).to receive(:exist?).with('/test/enable').and_return(false)
142
+ end
143
+ it { is_expected.to eq({}) }
144
+ end # /context with a non-existent file
145
+ end # /describe #parse_enable_file
146
+
147
+ describe '.provides_auto?' do
148
+ let(:node) { double('node') }
149
+ let(:new_resource) { double('resource') }
150
+ subject { provider(:poise_test).provides_auto?(node, new_resource) }
151
+ before do
152
+ allow(provider(:poise_test)).to receive(:inversion_options).with(node, new_resource).and_return({})
153
+ allow(provider(:poise_test)).to receive(:find_scl_package).with(node, nil).and_return({})
154
+ end
155
+ it { is_expected.to be true }
156
+ end # /describe .provides_auto?
157
+
158
+ describe '.find_scl_package' do
159
+ let(:version) { '' }
160
+ provider(:poise_test) do
161
+ include described_class
162
+ scl_package('3.4.2', 'rh-python34', {
163
+ ['redhat', 'centos'] => {
164
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
165
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm',
166
+ },
167
+ })
168
+ scl_package('3.3.2', 'python33', {
169
+ ['redhat', 'centos'] => {
170
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-7-x86_64/download/rhscl-python33-epel-7-x86_64.noarch.rpm',
171
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-6-x86_64/download/rhscl-python33-epel-6-x86_64.noarch.rpm',
172
+ },
173
+ 'fedora' => {
174
+ '~> 21.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/fedora-21-x86_64/download/rhscl-python33-fedora-21-x86_64.noarch.rpm',
175
+ '~> 20.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/fedora-20-x86_64/download/rhscl-python33-fedora-20-x86_64.noarch.rpm',
176
+ },
177
+ })
178
+ end
179
+ subject { provider(:poise_test).send(:find_scl_package, chef_run.node, version) }
180
+
181
+ context 'on CentOS 7 with no version' do
182
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
183
+ it do
184
+ is_expected.to include({
185
+ version: '3.4.2',
186
+ name: 'rh-python34',
187
+ url: 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
188
+ })
189
+ end
190
+ end # /context on CentOS 7 with no version
191
+
192
+ context 'on CentOS 6 with a version' do
193
+ let(:version) { '3.3' }
194
+ let(:chefspec_options) { {platform: 'centos', version: '6.0'} }
195
+ it do
196
+ is_expected.to include({
197
+ version: '3.3.2',
198
+ name: 'python33',
199
+ url: 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-6-x86_64/download/rhscl-python33-epel-6-x86_64.noarch.rpm',
200
+ })
201
+ end
202
+ end # /context on CentOS 6 with a version
203
+
204
+ context 'on Ubuntu' do
205
+ let(:chefspec_options) { {platform: 'ubuntu', version: '12.04'} }
206
+ it { is_expected.to be_nil }
207
+ end # /context on Ubuntu
208
+ end # /describe .find_scl_package
209
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseLanguages::Scl::Resource do
20
+ step_into(:poise_languages_scl)
21
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
22
+
23
+ context 'action :install' do
24
+ recipe do
25
+ r = ruby_block 'parent'
26
+ poise_languages_scl 'mylang' do
27
+ parent r
28
+ url 'http://mylang.rpm'
29
+ end
30
+ end
31
+
32
+ it { is_expected.to upgrade_package('scl-utils') }
33
+ it { is_expected.to install_rpm_package('rhscl-mylang').with(source: 'http://mylang.rpm') }
34
+ it { is_expected.to install_yum_package('mylang').with(flush_cache: {before: true}) }
35
+ end # /context action :install
36
+
37
+ context 'action :uninstall' do
38
+ recipe do
39
+ r = ruby_block 'parent'
40
+ poise_languages_scl 'mylang' do
41
+ action :uninstall
42
+ parent r
43
+ url 'http://mylang.rpm'
44
+ end
45
+ end
46
+
47
+ it { is_expected.to remove_package('scl-utils') }
48
+ it { is_expected.to remove_rpm_package('rhscl-mylang') }
49
+ it { is_expected.to remove_yum_package('mylang') }
50
+ end # /context action :uninstall
51
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_boiler/spec_helper'
18
+ require 'poise_languages'
@@ -0,0 +1,172 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseLanguages::System::Mixin do
20
+ resource(:poise_test)
21
+ provider(:poise_test) do
22
+ include described_class
23
+ end
24
+
25
+ describe '#install_system_packages' do
26
+ provider(:poise_test) do
27
+ include Poise
28
+ include described_class
29
+ def system_package_name
30
+ 'mylang'
31
+ end
32
+ def options
33
+ {}
34
+ end
35
+ def action_run
36
+ install_system_packages
37
+ end
38
+ end
39
+ recipe do
40
+ poise_test 'test'
41
+ end
42
+
43
+ it { is_expected.to install_poise_languages_system('mylang').with(parent: chef_run.poise_test('test'),
44
+ dev_package: nil,
45
+ dev_package_overrides: {},
46
+ package_version: nil,
47
+ version: '') }
48
+ end # /describe #install_system_packages
49
+
50
+ describe '#uninstall_system_packages' do
51
+ provider(:poise_test) do
52
+ include Poise
53
+ include described_class
54
+ def system_package_name
55
+ 'mylang'
56
+ end
57
+ def options
58
+ {}
59
+ end
60
+ def action_run
61
+ uninstall_system_packages
62
+ end
63
+ end
64
+ recipe do
65
+ poise_test 'test'
66
+ end
67
+
68
+ it { is_expected.to uninstall_poise_languages_system('mylang') }
69
+ end # /describe #uninstall_system_packages
70
+
71
+ describe '#system_package_candidates' do
72
+ subject { provider(:poise_test).new(nil, nil).send(:system_package_candidates, '') }
73
+ it { expect { subject }.to raise_error NotImplementedError }
74
+ end # /describe #system_package_candidates
75
+
76
+ describe '#system_package_name' do
77
+ let(:chefspec_options) { {platform: 'debian', version: '7.0'} }
78
+ let(:version) { '' }
79
+ let(:test_provider) { provider(:poise_test).new(nil, chef_run.run_context) }
80
+ provider(:poise_test) do
81
+ include described_class
82
+ packages('python', {
83
+ debian: {
84
+ '~> 8.0' => %w{python3.4 python2.7},
85
+ '~> 7.0' => %w{python3.2 python2.7 python2.6},
86
+ '~> 6.0' => %w{python3.1 python2.6 python2.5},
87
+ },
88
+ ubuntu: {
89
+ '14.04' => %w{python3.4 python2.7},
90
+ '12.04' => %w{python3.2 python2.7},
91
+ '10.04' => %w{python3.1 python2.6},
92
+ },
93
+ })
94
+
95
+ def system_package_candidates(version)
96
+ %w{python3.4 python3.3 python3.2 python3.1 python3.0 python2.7 python2.6}.select {|pkg| pkg.start_with?("python#{version}") } + %w{python}
97
+ end
98
+ end
99
+ subject { test_provider.send(:system_package_name) }
100
+ before do
101
+ allow(test_provider).to receive(:options).and_return({'version' => version})
102
+ end
103
+
104
+ context 'with a blank version' do
105
+ it { is_expected.to eq 'python3.2' }
106
+ end # /context with a blank version
107
+
108
+ context 'with version 3' do
109
+ let(:version) { '3' }
110
+ it { is_expected.to eq 'python3.2' }
111
+ end # /context with version 3
112
+
113
+ context 'with version 2' do
114
+ let(:version) { '2' }
115
+ it { is_expected.to eq 'python2.7' }
116
+ end # /context with version 2
117
+
118
+ context 'with version 2.6' do
119
+ let(:version) { '2.6' }
120
+ it { is_expected.to eq 'python2.6' }
121
+ end # /context with version 2.6
122
+
123
+ context 'on an unknown platform' do
124
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
125
+ it { is_expected.to eq 'python' }
126
+ end # /context on an unknown platform
127
+
128
+ context 'with no valid package' do
129
+ provider(:poise_test) do
130
+ include described_class
131
+ packages(nil, {})
132
+
133
+ def system_package_candidates(version)
134
+ []
135
+ end
136
+ end
137
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
138
+ end # /context with no valid package
139
+ end # /describe #system_package_name
140
+
141
+ describe '#system_dev_package_overrides' do
142
+ subject { provider(:poise_test).new(nil, nil).send(:system_dev_package_overrides) }
143
+ it { is_expected.to eq({}) }
144
+ end # /describe #system_dev_package_overrides
145
+
146
+ describe '.provides_auto?' do
147
+ provider(:poise_test) do
148
+ include Poise(inversion: :poise_test)
149
+ include described_class
150
+ end
151
+ subject { provider(:poise_test).provides_auto?(chef_run.node, nil) }
152
+
153
+ context 'on CentOS' do
154
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
155
+ it { is_expected.to be true}
156
+ end # /context on CentOS
157
+
158
+ context 'on an unknown platform' do
159
+ it { is_expected.to be false}
160
+ end # /context on an unknown platform
161
+ end # /describe .provides_auto?
162
+
163
+ describe '.default_inversion_options' do
164
+ provider(:poise_test) do
165
+ include Poise(inversion: :poise_test)
166
+ include described_class
167
+ end
168
+ subject { provider(:poise_test).default_inversion_options(nil, nil) }
169
+
170
+ it { is_expected.to be_a(Hash) }
171
+ end # /describe .default_inversion_options
172
+ end