poise-languages 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +32 -0
- data/LICENSE +202 -0
- data/README.md +27 -0
- data/Rakefile +17 -0
- data/lib/poise_languages.rb +25 -0
- data/lib/poise_languages/command.rb +25 -0
- data/lib/poise_languages/command/mixin.rb +231 -0
- data/lib/poise_languages/error.rb +21 -0
- data/lib/poise_languages/scl.rb +24 -0
- data/lib/poise_languages/scl/mixin.rb +110 -0
- data/lib/poise_languages/scl/resource.rb +124 -0
- data/lib/poise_languages/system.rb +24 -0
- data/lib/poise_languages/system/mixin.rb +165 -0
- data/lib/poise_languages/system/resource.rb +202 -0
- data/lib/poise_languages/utils.rb +49 -0
- data/lib/poise_languages/utils/which.rb +49 -0
- data/lib/poise_languages/version.rb +20 -0
- data/poise-languages.gemspec +40 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +22 -0
- data/test/spec/command/mixin_spec.rb +328 -0
- data/test/spec/scl/mixin_spec.rb +209 -0
- data/test/spec/scl/resource_spec.rb +51 -0
- data/test/spec/spec_helper.rb +18 -0
- data/test/spec/system/mixin_spec.rb +172 -0
- data/test/spec/system/resource_spec.rb +123 -0
- data/test/spec/utils/which_spec.rb +69 -0
- data/test/spec/utils_spec.rb +55 -0
- metadata +132 -0
@@ -0,0 +1,123 @@
|
|
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::Resource do
|
20
|
+
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
|
21
|
+
step_into(:poise_languages_system)
|
22
|
+
step_into(:package, unwrap_notifying_block: false)
|
23
|
+
provider(:package_hack, parent: Chef::Provider::Package) do
|
24
|
+
def load_current_resource
|
25
|
+
@current_resource = new_resource.class.new(new_resource.name, run_context)
|
26
|
+
current_resource.package_name(new_resource.package_name)
|
27
|
+
candidate = node['poise_candidate']
|
28
|
+
current = node['poise_current']
|
29
|
+
@candidate_version = if new_resource.package_name.is_a?(Array)
|
30
|
+
current_resource.version([current] * new_resource.package_name.length)
|
31
|
+
[candidate] * new_resource.package_name.length
|
32
|
+
else
|
33
|
+
current_resource.version(current)
|
34
|
+
candidate
|
35
|
+
end
|
36
|
+
current_resource
|
37
|
+
end
|
38
|
+
def install_package(name, version)
|
39
|
+
run_context.resource_collection << new_resource unless run_context.resource_collection.keys.include?(new_resource.to_s)
|
40
|
+
end
|
41
|
+
alias_method :upgrade_package, :install_package
|
42
|
+
alias_method :remove_package, :install_package
|
43
|
+
alias_method :purge_package, :install_package
|
44
|
+
end
|
45
|
+
recipe do
|
46
|
+
r = ruby_block 'parent'
|
47
|
+
poise_languages_system 'mylang' do
|
48
|
+
parent r
|
49
|
+
version ''
|
50
|
+
end
|
51
|
+
end
|
52
|
+
before do
|
53
|
+
# I can't use the provider resolver system easily because overrides like this
|
54
|
+
# don't work well with the Halite patcher.
|
55
|
+
allow_any_instance_of(Chef::Resource::Package).to receive(:provider).and_return(provider(:package_hack))
|
56
|
+
# Set our candidate version.
|
57
|
+
default_attributes[:poise_candidate] = '1.0'
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'on Ubuntu' do
|
61
|
+
it { is_expected.to install_package('mylang, mylang-dev') }
|
62
|
+
end # /context on Ubuntu
|
63
|
+
|
64
|
+
context 'on CentOS' do
|
65
|
+
let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
|
66
|
+
|
67
|
+
it { is_expected.to install_package('mylang') }
|
68
|
+
it { is_expected.to install_package('mylang-devel') }
|
69
|
+
end # /context on Ubuntu
|
70
|
+
|
71
|
+
context 'action :upgrade' do
|
72
|
+
recipe do
|
73
|
+
r = ruby_block 'parent'
|
74
|
+
poise_languages_system 'mylang' do
|
75
|
+
action :upgrade
|
76
|
+
parent r
|
77
|
+
version ''
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it { is_expected.to upgrade_package('mylang, mylang-dev') }
|
82
|
+
end # /context action :upgrade
|
83
|
+
|
84
|
+
context 'action :uninstall' do
|
85
|
+
recipe do
|
86
|
+
r = ruby_block 'parent'
|
87
|
+
poise_languages_system 'mylang' do
|
88
|
+
action :uninstall
|
89
|
+
parent r
|
90
|
+
version ''
|
91
|
+
end
|
92
|
+
end
|
93
|
+
before do
|
94
|
+
default_attributes[:poise_current] = '2.0'
|
95
|
+
end
|
96
|
+
|
97
|
+
it { is_expected.to purge_package('mylang, mylang-dev') }
|
98
|
+
end # /context action :uninstall
|
99
|
+
|
100
|
+
context 'with a matching version' do
|
101
|
+
recipe do
|
102
|
+
r = ruby_block 'parent'
|
103
|
+
poise_languages_system 'mylang' do
|
104
|
+
parent r
|
105
|
+
version '1'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it { is_expected.to install_package('mylang, mylang-dev') }
|
110
|
+
end # /context with a matching version
|
111
|
+
|
112
|
+
context 'with a non-matching version' do
|
113
|
+
recipe do
|
114
|
+
r = ruby_block 'parent'
|
115
|
+
poise_languages_system 'mylang' do
|
116
|
+
parent r
|
117
|
+
version '2'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it { expect { subject }.to raise_error PoiseLanguages::Error }
|
122
|
+
end # /context with a non-matching version
|
123
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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::Utils::Which do
|
20
|
+
let(:params) { [] }
|
21
|
+
let(:executables) { {} }
|
22
|
+
let(:env_path) { '' }
|
23
|
+
subject { described_class.which(*params) }
|
24
|
+
before do
|
25
|
+
executables.each do |path, value|
|
26
|
+
allow(File).to receive(:executable?).with(path).and_return(value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
around do |ex|
|
30
|
+
begin
|
31
|
+
old_path = ENV['PATH']
|
32
|
+
ENV['PATH'] = env_path
|
33
|
+
ex.run
|
34
|
+
ensure
|
35
|
+
ENV['PATH'] = old_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with no environment variable' do
|
40
|
+
let(:params) { ['myapp'] }
|
41
|
+
let(:executables) { {'/bin/myapp' => false, '/usr/bin/myapp' => false, '/sbin/myapp' => true} }
|
42
|
+
it { is_expected.to eq '/sbin/myapp' }
|
43
|
+
end # /context with no environment variable
|
44
|
+
|
45
|
+
context 'with extra_path' do
|
46
|
+
let(:params) { ['myapp', {extra_path: %w{/foo /bar}}] }
|
47
|
+
let(:executables) { {'/foo/myapp' => false, '/bar/myapp' => true} }
|
48
|
+
it { is_expected.to eq '/bar/myapp' }
|
49
|
+
end # /context with extra_path
|
50
|
+
|
51
|
+
context 'with $PATH' do
|
52
|
+
let(:params) { ['myapp'] }
|
53
|
+
let(:env_path) { %w{/something /other /nope}.join(File::PATH_SEPARATOR) }
|
54
|
+
let(:executables) { {'/something/myapp' => false, '/other/myapp' => true} }
|
55
|
+
it { is_expected.to eq '/other/myapp' }
|
56
|
+
end # /context with $PATH
|
57
|
+
|
58
|
+
context 'with path' do
|
59
|
+
let(:params) { ['myapp', {path: %w{/something /other /nope}.join(File::PATH_SEPARATOR)}] }
|
60
|
+
let(:executables) { {'/something/myapp' => false, '/other/myapp' => true} }
|
61
|
+
it { is_expected.to eq '/other/myapp' }
|
62
|
+
end # /context with path
|
63
|
+
|
64
|
+
context 'with a non-existent command' do
|
65
|
+
let(:params) { ['myapp'] }
|
66
|
+
let(:executables) { {'/bin/myapp' => false, '/usr/bin/myapp' => false, '/sbin/myapp' => false, '/usr/sbin/myapp' => false} }
|
67
|
+
it { is_expected.to be false }
|
68
|
+
end # /context with a non-existent command
|
69
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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::Utils do
|
20
|
+
describe '#absolute_command' do
|
21
|
+
let(:path) { double('path') }
|
22
|
+
let(:cmd) { }
|
23
|
+
let(:which) { '/bin/myapp' }
|
24
|
+
subject { described_class.absolute_command(cmd, path: path) }
|
25
|
+
before do
|
26
|
+
allow(described_class).to receive(:which).with('myapp', path: path).and_return(which)
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a string' do
|
30
|
+
let(:cmd) { 'myapp --port 8080' }
|
31
|
+
it { is_expected.to eq '/bin/myapp --port 8080' }
|
32
|
+
end # /context with a string
|
33
|
+
|
34
|
+
context 'with an array' do
|
35
|
+
let(:cmd) { %w{myapp --port 8080} }
|
36
|
+
it { is_expected.to eq %w{/bin/myapp --port 8080} }
|
37
|
+
end # /context with an array
|
38
|
+
|
39
|
+
context 'with options' do
|
40
|
+
let(:cmd) { '--port 8080' }
|
41
|
+
it { is_expected.to eq '--port 8080' }
|
42
|
+
end # /context with options
|
43
|
+
|
44
|
+
context 'with an unknown command' do
|
45
|
+
let(:cmd) { 'myapp --port 8080' }
|
46
|
+
let(:which) { false }
|
47
|
+
it { is_expected.to eq 'myapp --port 8080' }
|
48
|
+
end # /context with an unknown command
|
49
|
+
end # /describe #absolute_command
|
50
|
+
|
51
|
+
describe '#which' do
|
52
|
+
# See utils/which_spec.rb for real tests.
|
53
|
+
it { is_expected.to respond_to :which }
|
54
|
+
end # /describe #which
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poise-languages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Noah Kantrowitz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: halite
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: poise
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: poise-boiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: A Chef cookbook to help writing language cooobkoks.
|
56
|
+
email:
|
57
|
+
- noah@coderanger.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/poise_languages.rb
|
70
|
+
- lib/poise_languages/command.rb
|
71
|
+
- lib/poise_languages/command/mixin.rb
|
72
|
+
- lib/poise_languages/error.rb
|
73
|
+
- lib/poise_languages/scl.rb
|
74
|
+
- lib/poise_languages/scl/mixin.rb
|
75
|
+
- lib/poise_languages/scl/resource.rb
|
76
|
+
- lib/poise_languages/system.rb
|
77
|
+
- lib/poise_languages/system/mixin.rb
|
78
|
+
- lib/poise_languages/system/resource.rb
|
79
|
+
- lib/poise_languages/utils.rb
|
80
|
+
- lib/poise_languages/utils/which.rb
|
81
|
+
- lib/poise_languages/version.rb
|
82
|
+
- poise-languages.gemspec
|
83
|
+
- test/docker/docker.ca
|
84
|
+
- test/docker/docker.pem
|
85
|
+
- test/gemfiles/chef-12.gemfile
|
86
|
+
- test/gemfiles/master.gemfile
|
87
|
+
- test/spec/command/mixin_spec.rb
|
88
|
+
- test/spec/scl/mixin_spec.rb
|
89
|
+
- test/spec/scl/resource_spec.rb
|
90
|
+
- test/spec/spec_helper.rb
|
91
|
+
- test/spec/system/mixin_spec.rb
|
92
|
+
- test/spec/system/resource_spec.rb
|
93
|
+
- test/spec/utils/which_spec.rb
|
94
|
+
- test/spec/utils_spec.rb
|
95
|
+
homepage: https://github.com/poise/poise-languages
|
96
|
+
licenses:
|
97
|
+
- Apache 2.0
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.8
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: A Chef cookbook to help writing language cooobkoks.
|
119
|
+
test_files:
|
120
|
+
- test/docker/docker.ca
|
121
|
+
- test/docker/docker.pem
|
122
|
+
- test/gemfiles/chef-12.gemfile
|
123
|
+
- test/gemfiles/master.gemfile
|
124
|
+
- test/spec/command/mixin_spec.rb
|
125
|
+
- test/spec/scl/mixin_spec.rb
|
126
|
+
- test/spec/scl/resource_spec.rb
|
127
|
+
- test/spec/spec_helper.rb
|
128
|
+
- test/spec/system/mixin_spec.rb
|
129
|
+
- test/spec/system/resource_spec.rb
|
130
|
+
- test/spec/utils/which_spec.rb
|
131
|
+
- test/spec/utils_spec.rb
|
132
|
+
has_rdoc:
|