poise-derived 0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.kitchen.yml +3 -0
- data/.travis.yml +40 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +32 -0
- data/LICENSE +201 -0
- data/README.md +110 -0
- data/Rakefile +17 -0
- data/chef/recipes/default.rb +17 -0
- data/lib/poise_derived.rb +22 -0
- data/lib/poise_derived/cheftie.rb +18 -0
- data/lib/poise_derived/core_ext.rb +28 -0
- data/lib/poise_derived/core_ext/deep_merge.rb +55 -0
- data/lib/poise_derived/core_ext/string.rb +35 -0
- data/lib/poise_derived/dsl.rb +45 -0
- data/lib/poise_derived/handler.rb +43 -0
- data/lib/poise_derived/lazy_attribute.rb +125 -0
- data/lib/poise_derived/version.rb +20 -0
- data/poise-derived.gemspec +41 -0
- data/test/cookbook/attributes/default.rb +46 -0
- data/test/cookbook/metadata.rb +18 -0
- data/test/cookbook/recipes/default.rb +28 -0
- data/test/gemfiles/chef-12.10.gemfile +20 -0
- data/test/gemfiles/chef-12.11.gemfile +20 -0
- data/test/gemfiles/chef-12.12.gemfile +19 -0
- data/test/gemfiles/chef-12.13.gemfile +19 -0
- data/test/gemfiles/chef-12.14.gemfile +19 -0
- data/test/gemfiles/chef-12.3.gemfile +20 -0
- data/test/gemfiles/chef-12.4.gemfile +21 -0
- data/test/gemfiles/chef-12.5.gemfile +20 -0
- data/test/gemfiles/chef-12.6.gemfile +20 -0
- data/test/gemfiles/chef-12.7.gemfile +20 -0
- data/test/gemfiles/chef-12.8.gemfile +20 -0
- data/test/gemfiles/chef-12.9.gemfile +20 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +21 -0
- data/test/integration/default/serverspec/default_spec.rb +35 -0
- data/test/spec/lazy_attribute_spec.rb +158 -0
- data/test/spec/spec_helper.rb +21 -0
- metadata +123 -8
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
name 'poise-derived_test'
|
18
|
+
depends 'poise-derived'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
# Late override of some values.
|
18
|
+
node.override['f']['one'] = '2'
|
19
|
+
node.override['g']['one'] = '2'
|
20
|
+
node.override['h']['value'] = 'two %{h.two}'
|
21
|
+
|
22
|
+
directory '/test'
|
23
|
+
|
24
|
+
('a'..'i').each do |test|
|
25
|
+
file "/test/#{test}" do
|
26
|
+
content node[test]['value']
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.10.24'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.11.18'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.12.15'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.13.37'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.14.60'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.3.0'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.4.3'
|
20
|
+
gem 'rack', '< 2'
|
21
|
+
gem 'ridley', '4.4.1'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.5.1'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.6.0'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.7.2'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.8.1'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.9.41'
|
20
|
+
gem 'rack', '< 2'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', '~> 12.14'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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
|
+
eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
|
18
|
+
|
19
|
+
gem 'chef', github: 'chef/chef'
|
20
|
+
gem 'halite', github: 'poise/halite'
|
21
|
+
# gem 'poise-boiler', github: 'poise/poise-boiler'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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 'serverspec'
|
18
|
+
set :backend, :exec
|
19
|
+
|
20
|
+
# Test data to check.
|
21
|
+
{
|
22
|
+
'a' => 'a',
|
23
|
+
'b' => 'b',
|
24
|
+
'c' => '1',
|
25
|
+
'd' => 'd',
|
26
|
+
'e' => '1 2',
|
27
|
+
'f' => '2',
|
28
|
+
'g' => '2',
|
29
|
+
'h' => 'two 2',
|
30
|
+
'i' => 'two one 1 2',
|
31
|
+
}.each do |test, value|
|
32
|
+
describe file("/test/#{test}") do
|
33
|
+
its(:content) { is_expected.to eq value }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, 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 PoiseDerived::LazyAttribute do
|
20
|
+
subject { chef_run.node['url'] }
|
21
|
+
|
22
|
+
describe '#to_s' do
|
23
|
+
subject { chef_run.node['url'].to_s }
|
24
|
+
|
25
|
+
context 'with a string' do
|
26
|
+
recipe(subject: false) do
|
27
|
+
node.default['version'] = '1.0.0'
|
28
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
29
|
+
end
|
30
|
+
|
31
|
+
it { is_expected.to eq 'https://example.com/1.0.0' }
|
32
|
+
end # /context with a string
|
33
|
+
|
34
|
+
context 'with a block' do
|
35
|
+
recipe(subject: false) do
|
36
|
+
node.default['version'] = '1.0.0'
|
37
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node) { "https://example.com/#{node['version']}" }
|
38
|
+
end
|
39
|
+
|
40
|
+
it { is_expected.to eq 'https://example.com/1.0.0' }
|
41
|
+
end # /context with a block
|
42
|
+
end # /describe #to_s
|
43
|
+
|
44
|
+
describe '#inspect' do
|
45
|
+
subject { chef_run.node['url'].inspect }
|
46
|
+
|
47
|
+
context 'with a string' do
|
48
|
+
recipe(subject: false) do
|
49
|
+
node.default['version'] = '1.0.0'
|
50
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
51
|
+
end
|
52
|
+
|
53
|
+
it { is_expected.to eq '#<PoiseDerived::LazyAttribute @value="https://example.com/%{version}">' }
|
54
|
+
end # /context with a string
|
55
|
+
|
56
|
+
context 'with a block' do
|
57
|
+
recipe(subject: false) do
|
58
|
+
node.default['version'] = '1.0.0'
|
59
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node) { "https://example.com/#{node['version']}" }
|
60
|
+
end
|
61
|
+
|
62
|
+
it { is_expected.to eq '#<PoiseDerived::LazyAttribute @value=proc>' }
|
63
|
+
end # /context with a block
|
64
|
+
end # /describe #inspect
|
65
|
+
|
66
|
+
describe 'evaluation' do
|
67
|
+
context 'with no arguments' do
|
68
|
+
subject { described_class.new(nil) }
|
69
|
+
|
70
|
+
it { expect { subject }.to raise_error ArgumentError }
|
71
|
+
end # /context with no arguments
|
72
|
+
|
73
|
+
context 'with both arguments' do
|
74
|
+
subject { described_class.new(nil, '') { } }
|
75
|
+
|
76
|
+
it { expect { subject }.to raise_error ArgumentError }
|
77
|
+
end # /context with both arguments
|
78
|
+
|
79
|
+
context 'with a single replacement' do
|
80
|
+
recipe(subject: false) do
|
81
|
+
node.default['version'] = '1.0.0'
|
82
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
83
|
+
end
|
84
|
+
|
85
|
+
it { is_expected.to eq 'https://example.com/1.0.0' }
|
86
|
+
end # /context with a single replacement
|
87
|
+
|
88
|
+
context 'with a two replacements' do
|
89
|
+
recipe(subject: false) do
|
90
|
+
node.default['version'] = '1.0.0'
|
91
|
+
node.default['type'] = 'zip'
|
92
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}.%{type}')
|
93
|
+
end
|
94
|
+
|
95
|
+
it { is_expected.to eq 'https://example.com/1.0.0.zip' }
|
96
|
+
end # /context with a two replacements
|
97
|
+
|
98
|
+
context 'with a nested replacement' do
|
99
|
+
subject { chef_run.node['myapp']['url'] }
|
100
|
+
recipe(subject: false) do
|
101
|
+
node.default['myapp']['version'] = '1.0.0'
|
102
|
+
node.default['myapp']['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{myapp.version}')
|
103
|
+
end
|
104
|
+
|
105
|
+
it { is_expected.to eq 'https://example.com/1.0.0' }
|
106
|
+
end # /context with a nested replacement
|
107
|
+
|
108
|
+
context 'with an overridden replacement' do
|
109
|
+
recipe(subject: false) do
|
110
|
+
node.default['version'] = '1.0.0'
|
111
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
112
|
+
node.override['version'] = '2.0.0'
|
113
|
+
end
|
114
|
+
|
115
|
+
it { is_expected.to eq 'https://example.com/2.0.0' }
|
116
|
+
end # /context with an overridden replacement
|
117
|
+
|
118
|
+
context 'with an overriden template' do
|
119
|
+
recipe(subject: false) do
|
120
|
+
node.default['version'] = '1.0.0'
|
121
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
122
|
+
node.override['url'] = 'https://example.net/%{version}'
|
123
|
+
end
|
124
|
+
|
125
|
+
it { is_expected.to eq 'https://example.net/1.0.0' }
|
126
|
+
end # /context with an overriden template
|
127
|
+
|
128
|
+
context 'with a block' do
|
129
|
+
recipe(subject: false) do
|
130
|
+
node.default['version'] = '1.0.0'
|
131
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node) { "https://example.com/#{node['version']}" }
|
132
|
+
end
|
133
|
+
|
134
|
+
it { is_expected.to eq 'https://example.com/1.0.0' }
|
135
|
+
end # /context with a block
|
136
|
+
|
137
|
+
context 'with a double-lazy chain' do
|
138
|
+
recipe(subject: false) do
|
139
|
+
node.default['version'] = '1.0.0'
|
140
|
+
node.default['url_part'] = PoiseDerived::LazyAttribute.new(node, 'https://example.com/%{version}')
|
141
|
+
node.default['url'] = PoiseDerived::LazyAttribute.new(node, '%{url_part}.zip')
|
142
|
+
end
|
143
|
+
|
144
|
+
it { is_expected.to eq 'https://example.com/1.0.0.zip' }
|
145
|
+
end # /context with a double-lazy chain
|
146
|
+
end #/ describe evaluation
|
147
|
+
|
148
|
+
describe 'use in a resource' do
|
149
|
+
recipe do
|
150
|
+
node.default['content'] = PoiseDerived::LazyAttribute.new(node, 'content')
|
151
|
+
file '/test' do
|
152
|
+
content node['content']
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it { is_expected.to render_file('/test').with_content('content') }
|
157
|
+
end # /describe use in a resource
|
158
|
+
end
|