chef-utils 18.0.172 → 18.0.185
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/Rakefile +15 -15
- data/chef-utils.gemspec +50 -50
- data/lib/chef-utils/dist.rb +154 -154
- data/lib/chef-utils/dsl/architecture.rb +150 -150
- data/lib/chef-utils/dsl/cloud.rb +155 -155
- data/lib/chef-utils/dsl/default_paths.rb +60 -60
- data/lib/chef-utils/dsl/introspection.rb +134 -134
- data/lib/chef-utils/dsl/os.rb +58 -58
- data/lib/chef-utils/dsl/path_sanity.rb +39 -39
- data/lib/chef-utils/dsl/platform.rb +387 -387
- data/lib/chef-utils/dsl/platform_family.rb +360 -360
- data/lib/chef-utils/dsl/platform_version.rb +41 -41
- data/lib/chef-utils/dsl/service.rb +112 -112
- data/lib/chef-utils/dsl/train_helpers.rb +87 -87
- data/lib/chef-utils/dsl/virtualization.rb +272 -272
- data/lib/chef-utils/dsl/which.rb +123 -123
- data/lib/chef-utils/dsl/windows.rb +86 -86
- data/lib/chef-utils/internal.rb +114 -114
- data/lib/chef-utils/mash.rb +263 -263
- data/lib/chef-utils/parallel_map.rb +131 -131
- data/lib/chef-utils/version.rb +20 -20
- data/lib/chef-utils/version_string.rb +160 -160
- data/lib/chef-utils.rb +53 -53
- data/spec/spec_helper.rb +100 -100
- data/spec/unit/dsl/architecture_spec.rb +151 -151
- data/spec/unit/dsl/cloud_spec.rb +93 -93
- data/spec/unit/dsl/dsl_spec.rb +34 -34
- data/spec/unit/dsl/introspection_spec.rb +201 -201
- data/spec/unit/dsl/os_spec.rb +175 -175
- data/spec/unit/dsl/path_sanity_spec.rb +86 -86
- data/spec/unit/dsl/platform_family_spec.rb +235 -235
- data/spec/unit/dsl/platform_spec.rb +252 -252
- data/spec/unit/dsl/service_spec.rb +117 -117
- data/spec/unit/dsl/virtualization_spec.rb +75 -75
- data/spec/unit/dsl/which_spec.rb +171 -171
- data/spec/unit/dsl/windows_spec.rb +84 -84
- data/spec/unit/mash_spec.rb +51 -51
- data/spec/unit/parallel_map_spec.rb +156 -156
- metadata +7 -7
data/spec/unit/dsl/cloud_spec.rb
CHANGED
@@ -1,93 +1,93 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "spec_helper"
|
20
|
-
require "fauxhai"
|
21
|
-
|
22
|
-
def cloud_reports_true_for(*args, node:)
|
23
|
-
args.each do |method|
|
24
|
-
it "reports true for #{method}" do
|
25
|
-
expect(described_class.send(method, node)).to be true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
(CLOUD_HELPERS - args).each do |method|
|
29
|
-
it "reports false for #{method}" do
|
30
|
-
expect(described_class.send(method, node)).to be false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
RSpec.describe ChefUtils::DSL::Cloud do
|
36
|
-
( HELPER_MODULES - [ described_class ] ).each do |klass|
|
37
|
-
it "does not have methods that collide with #{klass}" do
|
38
|
-
expect((klass.methods - Module.methods) & CLOUD_HELPERS).to be_empty
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
CLOUD_HELPERS.each do |helper|
|
43
|
-
it "has the #{helper} in the ChefUtils module" do
|
44
|
-
expect(ChefUtils).to respond_to(helper)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "on alibaba" do
|
49
|
-
cloud_reports_true_for(:cloud?, :alibaba?, node: { "alibaba" => {}, "cloud" => {} })
|
50
|
-
end
|
51
|
-
|
52
|
-
context "on ec2" do
|
53
|
-
cloud_reports_true_for(:cloud?, :ec2?, node: { "ec2" => {}, "cloud" => {} })
|
54
|
-
end
|
55
|
-
|
56
|
-
context "on gce" do
|
57
|
-
cloud_reports_true_for(:cloud?, :gce?, node: { "gce" => {}, "cloud" => {} })
|
58
|
-
end
|
59
|
-
|
60
|
-
context "on rackspace" do
|
61
|
-
cloud_reports_true_for(:cloud?, :rackspace?, node: { "rackspace" => {}, "cloud" => {} })
|
62
|
-
end
|
63
|
-
|
64
|
-
context "on eucalyptus" do
|
65
|
-
cloud_reports_true_for(:cloud?, :eucalyptus?, :euca?, node: { "eucalyptus" => {}, "cloud" => {} })
|
66
|
-
end
|
67
|
-
|
68
|
-
context "on linode" do
|
69
|
-
cloud_reports_true_for(:cloud?, :linode?, node: { "linode" => {}, "cloud" => {} })
|
70
|
-
end
|
71
|
-
|
72
|
-
context "on openstack" do
|
73
|
-
cloud_reports_true_for(:cloud?, :openstack?, node: { "openstack" => {}, "cloud" => {} })
|
74
|
-
end
|
75
|
-
|
76
|
-
context "on azure" do
|
77
|
-
cloud_reports_true_for(:cloud?, :azure?, node: { "azure" => {}, "cloud" => {} })
|
78
|
-
end
|
79
|
-
|
80
|
-
context "on digital_ocean" do
|
81
|
-
cloud_reports_true_for(:cloud?, :digital_ocean?, :digitalocean?, node: { "digital_ocean" => {}, "cloud" => {} })
|
82
|
-
end
|
83
|
-
|
84
|
-
context "on softlayer" do
|
85
|
-
cloud_reports_true_for(:cloud?, :softlayer?, node: { "softlayer" => {}, "cloud" => {} })
|
86
|
-
end
|
87
|
-
|
88
|
-
context "on virtualbox" do
|
89
|
-
it "does not return true for cloud?" do
|
90
|
-
expect(described_class.cloud?({ "virtualbox" => {}, "cloud" => nil })).to be false
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
require "fauxhai"
|
21
|
+
|
22
|
+
def cloud_reports_true_for(*args, node:)
|
23
|
+
args.each do |method|
|
24
|
+
it "reports true for #{method}" do
|
25
|
+
expect(described_class.send(method, node)).to be true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
(CLOUD_HELPERS - args).each do |method|
|
29
|
+
it "reports false for #{method}" do
|
30
|
+
expect(described_class.send(method, node)).to be false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.describe ChefUtils::DSL::Cloud do
|
36
|
+
( HELPER_MODULES - [ described_class ] ).each do |klass|
|
37
|
+
it "does not have methods that collide with #{klass}" do
|
38
|
+
expect((klass.methods - Module.methods) & CLOUD_HELPERS).to be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
CLOUD_HELPERS.each do |helper|
|
43
|
+
it "has the #{helper} in the ChefUtils module" do
|
44
|
+
expect(ChefUtils).to respond_to(helper)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "on alibaba" do
|
49
|
+
cloud_reports_true_for(:cloud?, :alibaba?, node: { "alibaba" => {}, "cloud" => {} })
|
50
|
+
end
|
51
|
+
|
52
|
+
context "on ec2" do
|
53
|
+
cloud_reports_true_for(:cloud?, :ec2?, node: { "ec2" => {}, "cloud" => {} })
|
54
|
+
end
|
55
|
+
|
56
|
+
context "on gce" do
|
57
|
+
cloud_reports_true_for(:cloud?, :gce?, node: { "gce" => {}, "cloud" => {} })
|
58
|
+
end
|
59
|
+
|
60
|
+
context "on rackspace" do
|
61
|
+
cloud_reports_true_for(:cloud?, :rackspace?, node: { "rackspace" => {}, "cloud" => {} })
|
62
|
+
end
|
63
|
+
|
64
|
+
context "on eucalyptus" do
|
65
|
+
cloud_reports_true_for(:cloud?, :eucalyptus?, :euca?, node: { "eucalyptus" => {}, "cloud" => {} })
|
66
|
+
end
|
67
|
+
|
68
|
+
context "on linode" do
|
69
|
+
cloud_reports_true_for(:cloud?, :linode?, node: { "linode" => {}, "cloud" => {} })
|
70
|
+
end
|
71
|
+
|
72
|
+
context "on openstack" do
|
73
|
+
cloud_reports_true_for(:cloud?, :openstack?, node: { "openstack" => {}, "cloud" => {} })
|
74
|
+
end
|
75
|
+
|
76
|
+
context "on azure" do
|
77
|
+
cloud_reports_true_for(:cloud?, :azure?, node: { "azure" => {}, "cloud" => {} })
|
78
|
+
end
|
79
|
+
|
80
|
+
context "on digital_ocean" do
|
81
|
+
cloud_reports_true_for(:cloud?, :digital_ocean?, :digitalocean?, node: { "digital_ocean" => {}, "cloud" => {} })
|
82
|
+
end
|
83
|
+
|
84
|
+
context "on softlayer" do
|
85
|
+
cloud_reports_true_for(:cloud?, :softlayer?, node: { "softlayer" => {}, "cloud" => {} })
|
86
|
+
end
|
87
|
+
|
88
|
+
context "on virtualbox" do
|
89
|
+
it "does not return true for cloud?" do
|
90
|
+
expect(described_class.cloud?({ "virtualbox" => {}, "cloud" => nil })).to be false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/spec/unit/dsl/dsl_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "spec_helper"
|
20
|
-
|
21
|
-
RSpec.describe ChefUtils do
|
22
|
-
class ThingWithDSL
|
23
|
-
extend ChefUtils
|
24
|
-
end
|
25
|
-
|
26
|
-
(OS_HELPERS + ARCH_HELPERS + PLATFORM_HELPERS + PLATFORM_FAMILY_HELPERS + INTROSPECTION_HELPERS).each do |helper|
|
27
|
-
it "has the #{helper} in the ChefUtils module" do
|
28
|
-
expect(ThingWithDSL).to respond_to(helper)
|
29
|
-
end
|
30
|
-
it "has the #{helper} class method in the ChefUtils module" do
|
31
|
-
expect(ChefUtils).to respond_to(helper)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
RSpec.describe ChefUtils do
|
22
|
+
class ThingWithDSL
|
23
|
+
extend ChefUtils
|
24
|
+
end
|
25
|
+
|
26
|
+
(OS_HELPERS + ARCH_HELPERS + PLATFORM_HELPERS + PLATFORM_FAMILY_HELPERS + INTROSPECTION_HELPERS).each do |helper|
|
27
|
+
it "has the #{helper} in the ChefUtils module" do
|
28
|
+
expect(ThingWithDSL).to respond_to(helper)
|
29
|
+
end
|
30
|
+
it "has the #{helper} class method in the ChefUtils module" do
|
31
|
+
expect(ChefUtils).to respond_to(helper)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,201 +1,201 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "spec_helper"
|
20
|
-
|
21
|
-
RSpec.describe ChefUtils::DSL::Introspection do
|
22
|
-
class IntrospectionTestClass
|
23
|
-
include ChefUtils::DSL::Introspection
|
24
|
-
attr_accessor :node
|
25
|
-
|
26
|
-
def initialize(node)
|
27
|
-
@node = node
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:node) { double("node") }
|
32
|
-
|
33
|
-
let(:test_instance) { IntrospectionTestClass.new(node) }
|
34
|
-
|
35
|
-
context "#effortless?" do
|
36
|
-
# FIXME: use a real VividMash for these tests instead of stubbing
|
37
|
-
it "is false by default" do
|
38
|
-
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(nil)
|
39
|
-
expect(ChefUtils.effortless?(node)).to be false
|
40
|
-
end
|
41
|
-
it "is true when ohai reports a effortless" do
|
42
|
-
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(true)
|
43
|
-
expect(ChefUtils.effortless?(node)).to be true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "#docker?" do
|
48
|
-
# FIXME: use a real VividMash for these tests instead of stubbing
|
49
|
-
it "is false by default" do
|
50
|
-
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return(nil)
|
51
|
-
expect(ChefUtils.docker?(node)).to be false
|
52
|
-
end
|
53
|
-
it "is true when ohai reports a docker guest" do
|
54
|
-
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("guest")
|
55
|
-
expect(ChefUtils.docker?(node)).to be true
|
56
|
-
end
|
57
|
-
it "is false for any other value other than guest" do
|
58
|
-
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("some nonsense")
|
59
|
-
expect(ChefUtils.docker?(node)).to be false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "#systemd?" do
|
64
|
-
# FIXME: somehow test the train helpers
|
65
|
-
it "returns false if /proc/1/comm does not exist" do
|
66
|
-
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(false)
|
67
|
-
expect(ChefUtils.systemd?(node)).to be false
|
68
|
-
end
|
69
|
-
|
70
|
-
it "returns false if /proc/1/comm is not systemd" do
|
71
|
-
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
72
|
-
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("upstart\n"))
|
73
|
-
expect(ChefUtils.systemd?(node)).to be false
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns true if /proc/1/comm is systemd" do
|
77
|
-
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
78
|
-
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("systemd\n"))
|
79
|
-
expect(ChefUtils.systemd?(node)).to be true
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "#kitchen?" do
|
84
|
-
before do
|
85
|
-
@saved = ENV["TEST_KITCHEN"]
|
86
|
-
end
|
87
|
-
after do
|
88
|
-
ENV["TEST_KITCHEN"] = @saved
|
89
|
-
end
|
90
|
-
|
91
|
-
it "return true if ENV['TEST_KITCHEN'] is not set" do
|
92
|
-
ENV.delete("TEST_KITCHEN")
|
93
|
-
expect(ChefUtils.kitchen?(node)).to be false
|
94
|
-
end
|
95
|
-
|
96
|
-
it "return true if ENV['TEST_KITCHEN'] is nil" do
|
97
|
-
ENV["TEST_KITCHEN"] = nil
|
98
|
-
expect(ChefUtils.kitchen?(node)).to be false
|
99
|
-
end
|
100
|
-
|
101
|
-
it "return true if ENV['TEST_KITCHEN'] is set" do
|
102
|
-
ENV["TEST_KITCHEN"] = "1"
|
103
|
-
expect(ChefUtils.kitchen?(node)).to be true
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "#ci?" do
|
108
|
-
before do
|
109
|
-
@saved = ENV["CI"]
|
110
|
-
end
|
111
|
-
after do
|
112
|
-
ENV["CI"] = @saved
|
113
|
-
end
|
114
|
-
|
115
|
-
it "return true if ENV['CI'] is not set" do
|
116
|
-
ENV.delete("CI")
|
117
|
-
expect(ChefUtils.ci?(node)).to be false
|
118
|
-
end
|
119
|
-
|
120
|
-
it "return true if ENV['CI'] is nil" do
|
121
|
-
ENV["CI"] = nil
|
122
|
-
expect(ChefUtils.ci?(node)).to be false
|
123
|
-
end
|
124
|
-
|
125
|
-
it "return true if ENV['CI'] is set" do
|
126
|
-
ENV["CI"] = "1"
|
127
|
-
expect(ChefUtils.ci?(node)).to be true
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context "#has_systemd_service_unit?" do
|
132
|
-
# FIXME: test through train helpers
|
133
|
-
|
134
|
-
before do
|
135
|
-
%w{ /etc /usr/lib /lib /run }.each do |base|
|
136
|
-
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(false)
|
137
|
-
allow(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(false)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
it "is false if no unit is present" do
|
142
|
-
expect(ChefUtils.has_systemd_service_unit?("example")).to be false
|
143
|
-
end
|
144
|
-
|
145
|
-
it "is false if no template is present" do
|
146
|
-
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be false
|
147
|
-
end
|
148
|
-
|
149
|
-
%w{ /etc /usr/lib /lib /run }.each do |base|
|
150
|
-
it "finds a unit in #{base}" do
|
151
|
-
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(true)
|
152
|
-
expect(ChefUtils.has_systemd_service_unit?("example")).to be true
|
153
|
-
end
|
154
|
-
|
155
|
-
it "finds a template in #{base}" do
|
156
|
-
expect(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(true)
|
157
|
-
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be true
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "#has_systemd_unit?" do
|
163
|
-
# FIXME: test through train helpers
|
164
|
-
|
165
|
-
before do
|
166
|
-
%w{ /etc /usr/lib /lib /run }.each do |base|
|
167
|
-
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(false)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
it "is false if no unit is present" do
|
172
|
-
expect(ChefUtils.has_systemd_unit?("example.mount")).to be false
|
173
|
-
end
|
174
|
-
|
175
|
-
%w{ /etc /usr/lib /lib /run }.each do |base|
|
176
|
-
it "finds a unit in #{base}" do
|
177
|
-
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(true)
|
178
|
-
expect(ChefUtils.has_systemd_unit?("example.mount")).to be true
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "#include_recipe?" do
|
184
|
-
it "is true when the recipe has been seen by the node" do
|
185
|
-
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
186
|
-
expect(ChefUtils.include_recipe?("myrecipe", node)).to be true
|
187
|
-
end
|
188
|
-
it "is false when the recipe has not been seen by the node" do
|
189
|
-
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
190
|
-
expect(ChefUtils.include_recipe?("myrecipe", node)).to be false
|
191
|
-
end
|
192
|
-
it "the alias is true when the recipe has been seen by the node" do
|
193
|
-
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
194
|
-
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be true
|
195
|
-
end
|
196
|
-
it "the alias is false when the recipe has not been seen by the node" do
|
197
|
-
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
198
|
-
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be false
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
RSpec.describe ChefUtils::DSL::Introspection do
|
22
|
+
class IntrospectionTestClass
|
23
|
+
include ChefUtils::DSL::Introspection
|
24
|
+
attr_accessor :node
|
25
|
+
|
26
|
+
def initialize(node)
|
27
|
+
@node = node
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:node) { double("node") }
|
32
|
+
|
33
|
+
let(:test_instance) { IntrospectionTestClass.new(node) }
|
34
|
+
|
35
|
+
context "#effortless?" do
|
36
|
+
# FIXME: use a real VividMash for these tests instead of stubbing
|
37
|
+
it "is false by default" do
|
38
|
+
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(nil)
|
39
|
+
expect(ChefUtils.effortless?(node)).to be false
|
40
|
+
end
|
41
|
+
it "is true when ohai reports a effortless" do
|
42
|
+
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(true)
|
43
|
+
expect(ChefUtils.effortless?(node)).to be true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#docker?" do
|
48
|
+
# FIXME: use a real VividMash for these tests instead of stubbing
|
49
|
+
it "is false by default" do
|
50
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return(nil)
|
51
|
+
expect(ChefUtils.docker?(node)).to be false
|
52
|
+
end
|
53
|
+
it "is true when ohai reports a docker guest" do
|
54
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("guest")
|
55
|
+
expect(ChefUtils.docker?(node)).to be true
|
56
|
+
end
|
57
|
+
it "is false for any other value other than guest" do
|
58
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("some nonsense")
|
59
|
+
expect(ChefUtils.docker?(node)).to be false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#systemd?" do
|
64
|
+
# FIXME: somehow test the train helpers
|
65
|
+
it "returns false if /proc/1/comm does not exist" do
|
66
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(false)
|
67
|
+
expect(ChefUtils.systemd?(node)).to be false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns false if /proc/1/comm is not systemd" do
|
71
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
72
|
+
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("upstart\n"))
|
73
|
+
expect(ChefUtils.systemd?(node)).to be false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns true if /proc/1/comm is systemd" do
|
77
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
78
|
+
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("systemd\n"))
|
79
|
+
expect(ChefUtils.systemd?(node)).to be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "#kitchen?" do
|
84
|
+
before do
|
85
|
+
@saved = ENV["TEST_KITCHEN"]
|
86
|
+
end
|
87
|
+
after do
|
88
|
+
ENV["TEST_KITCHEN"] = @saved
|
89
|
+
end
|
90
|
+
|
91
|
+
it "return true if ENV['TEST_KITCHEN'] is not set" do
|
92
|
+
ENV.delete("TEST_KITCHEN")
|
93
|
+
expect(ChefUtils.kitchen?(node)).to be false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "return true if ENV['TEST_KITCHEN'] is nil" do
|
97
|
+
ENV["TEST_KITCHEN"] = nil
|
98
|
+
expect(ChefUtils.kitchen?(node)).to be false
|
99
|
+
end
|
100
|
+
|
101
|
+
it "return true if ENV['TEST_KITCHEN'] is set" do
|
102
|
+
ENV["TEST_KITCHEN"] = "1"
|
103
|
+
expect(ChefUtils.kitchen?(node)).to be true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "#ci?" do
|
108
|
+
before do
|
109
|
+
@saved = ENV["CI"]
|
110
|
+
end
|
111
|
+
after do
|
112
|
+
ENV["CI"] = @saved
|
113
|
+
end
|
114
|
+
|
115
|
+
it "return true if ENV['CI'] is not set" do
|
116
|
+
ENV.delete("CI")
|
117
|
+
expect(ChefUtils.ci?(node)).to be false
|
118
|
+
end
|
119
|
+
|
120
|
+
it "return true if ENV['CI'] is nil" do
|
121
|
+
ENV["CI"] = nil
|
122
|
+
expect(ChefUtils.ci?(node)).to be false
|
123
|
+
end
|
124
|
+
|
125
|
+
it "return true if ENV['CI'] is set" do
|
126
|
+
ENV["CI"] = "1"
|
127
|
+
expect(ChefUtils.ci?(node)).to be true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "#has_systemd_service_unit?" do
|
132
|
+
# FIXME: test through train helpers
|
133
|
+
|
134
|
+
before do
|
135
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
136
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(false)
|
137
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(false)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "is false if no unit is present" do
|
142
|
+
expect(ChefUtils.has_systemd_service_unit?("example")).to be false
|
143
|
+
end
|
144
|
+
|
145
|
+
it "is false if no template is present" do
|
146
|
+
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be false
|
147
|
+
end
|
148
|
+
|
149
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
150
|
+
it "finds a unit in #{base}" do
|
151
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(true)
|
152
|
+
expect(ChefUtils.has_systemd_service_unit?("example")).to be true
|
153
|
+
end
|
154
|
+
|
155
|
+
it "finds a template in #{base}" do
|
156
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(true)
|
157
|
+
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be true
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "#has_systemd_unit?" do
|
163
|
+
# FIXME: test through train helpers
|
164
|
+
|
165
|
+
before do
|
166
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
167
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(false)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "is false if no unit is present" do
|
172
|
+
expect(ChefUtils.has_systemd_unit?("example.mount")).to be false
|
173
|
+
end
|
174
|
+
|
175
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
176
|
+
it "finds a unit in #{base}" do
|
177
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(true)
|
178
|
+
expect(ChefUtils.has_systemd_unit?("example.mount")).to be true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "#include_recipe?" do
|
184
|
+
it "is true when the recipe has been seen by the node" do
|
185
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
186
|
+
expect(ChefUtils.include_recipe?("myrecipe", node)).to be true
|
187
|
+
end
|
188
|
+
it "is false when the recipe has not been seen by the node" do
|
189
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
190
|
+
expect(ChefUtils.include_recipe?("myrecipe", node)).to be false
|
191
|
+
end
|
192
|
+
it "the alias is true when the recipe has been seen by the node" do
|
193
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
194
|
+
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be true
|
195
|
+
end
|
196
|
+
it "the alias is false when the recipe has not been seen by the node" do
|
197
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
198
|
+
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be false
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|