chef-utils 18.0.169 → 18.0.172
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/which_spec.rb
CHANGED
@@ -1,171 +1,171 @@
|
|
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::Which do
|
22
|
-
|
23
|
-
class WhichTestClass
|
24
|
-
include ChefUtils::DSL::Which
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:test) { WhichTestClass.new }
|
28
|
-
|
29
|
-
describe "#which" do
|
30
|
-
def self.test_which(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: nil, others: [], directory: false, &block)
|
31
|
-
it description do
|
32
|
-
# stub the ENV['PATH']
|
33
|
-
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
34
|
-
expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
|
35
|
-
|
36
|
-
# most files should not be found
|
37
|
-
allow(File).to receive(:executable?).and_return(false)
|
38
|
-
allow(File).to receive(:directory?).and_return(false)
|
39
|
-
|
40
|
-
# stub the expectation
|
41
|
-
expect(File).to receive(:executable?).with(finds).and_return(true) if finds
|
42
|
-
|
43
|
-
# if the file we find is a directory
|
44
|
-
expect(File).to receive(:directory?).with(finds).and_return(true) if finds && directory
|
45
|
-
|
46
|
-
# allow for stubbing other paths to exist that we should not find
|
47
|
-
others.each do |other|
|
48
|
-
allow(File).to receive(:executable?).with(other).and_return(true)
|
49
|
-
end
|
50
|
-
|
51
|
-
# setup the actual expectation on the return value
|
52
|
-
if finds && !directory
|
53
|
-
expect(test.which(*args, &block)).to eql(finds)
|
54
|
-
else
|
55
|
-
expect(test.which(*args, &block)).to eql(false)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "simple usage" do
|
61
|
-
test_which("returns false when it does not find anything", "foo1")
|
62
|
-
|
63
|
-
["/dir1", "/dir2" ].each do |dir|
|
64
|
-
test_which("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: "#{dir}/foo1")
|
65
|
-
end
|
66
|
-
|
67
|
-
test_which("does not find an executable directory", "foo1", finds: "/dir1/foo1", directory: true)
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with an array of args" do
|
71
|
-
test_which("finds the first arg", "foo1", "foo2", finds: "/dir2/foo1")
|
72
|
-
|
73
|
-
test_which("finds the second arg", "foo1", "foo2", finds: "/dir2/foo2")
|
74
|
-
|
75
|
-
test_which("finds the first arg when there's both", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ])
|
76
|
-
|
77
|
-
test_which("and the directory order can be reversed", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir2/foo2" ])
|
78
|
-
|
79
|
-
test_which("or be the same", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir1/foo2" ])
|
80
|
-
end
|
81
|
-
|
82
|
-
context "with a block" do
|
83
|
-
test_which("doesn't find it if its false", "foo1", others: [ "/dir1/foo1" ]) do |f|
|
84
|
-
false
|
85
|
-
end
|
86
|
-
|
87
|
-
test_which("finds it if its true", "foo1", finds: "/dir1/foo1") do |f|
|
88
|
-
true
|
89
|
-
end
|
90
|
-
|
91
|
-
test_which("passes in the filename as the arg", "foo1", finds: "/dir1/foo1") do |f|
|
92
|
-
raise "bad arg to block" unless f == "/dir1/foo1"
|
93
|
-
|
94
|
-
true
|
95
|
-
end
|
96
|
-
|
97
|
-
test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f|
|
98
|
-
raise "bad arg to block" unless ["/dir2/foo1", "/dir1/foo2"].include?(f)
|
99
|
-
|
100
|
-
true
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "nil path" do
|
105
|
-
test_which("returns false when it does not find anything", "foo1", path: nil)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "#where" do
|
110
|
-
def self.test_where(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: [], others: [], &block)
|
111
|
-
it description do
|
112
|
-
# stub the ENV['PATH']
|
113
|
-
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
114
|
-
expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
|
115
|
-
|
116
|
-
# most files should not be found
|
117
|
-
allow(File).to receive(:executable?).and_return(false)
|
118
|
-
allow(File).to receive(:directory?).and_return(false)
|
119
|
-
|
120
|
-
# allow for stubbing other paths to exist that we should not return
|
121
|
-
others.each do |other|
|
122
|
-
allow(File).to receive(:executable?).with(other).and_return(true)
|
123
|
-
end
|
124
|
-
|
125
|
-
# stub the expectation
|
126
|
-
finds.each do |path|
|
127
|
-
expect(File).to receive(:executable?).with(path).and_return(true)
|
128
|
-
end
|
129
|
-
|
130
|
-
# setup the actual expectation on the return value
|
131
|
-
expect(test.where(*args, &block)).to eql(finds)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "simple usage" do
|
136
|
-
test_where("returns empty array when it doesn't find anything", "foo1")
|
137
|
-
|
138
|
-
["/dir1", "/dir2" ].each do |dir|
|
139
|
-
test_where("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: [ "#{dir}/foo1" ])
|
140
|
-
end
|
141
|
-
|
142
|
-
test_where("finds `foo1` in all directories", "foo1", finds: [ "/dir1/foo1", "/dir2/foo1" ])
|
143
|
-
end
|
144
|
-
|
145
|
-
context "with an array of args" do
|
146
|
-
test_where("finds the first arg", "foo1", "foo2", finds: [ "/dir2/foo1" ])
|
147
|
-
|
148
|
-
test_where("finds the second arg", "foo1", "foo2", finds: [ "/dir2/foo2" ])
|
149
|
-
|
150
|
-
test_where("finds foo1 before foo2 if the dirs are reversed", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir2/foo2" ])
|
151
|
-
|
152
|
-
test_where("finds them both in the same directory", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir1/foo2" ])
|
153
|
-
|
154
|
-
test_where("finds foo2 first if they're reversed", "foo2", "foo1", finds: [ "/dir1/foo2", "/dir1/foo1" ])
|
155
|
-
end
|
156
|
-
|
157
|
-
context "with a block do" do
|
158
|
-
test_where("finds foo1 and foo2 if they exist and the block is true", "foo1", "foo2", finds: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
159
|
-
true
|
160
|
-
end
|
161
|
-
|
162
|
-
test_where("does not finds foo1 and foo2 if they exist and the block is false", "foo1", "foo2", others: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
163
|
-
false
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "with a nil path" do
|
168
|
-
test_where("returns empty array when it doesn't find anything", "foo1", path: nil)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
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::Which do
|
22
|
+
|
23
|
+
class WhichTestClass
|
24
|
+
include ChefUtils::DSL::Which
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:test) { WhichTestClass.new }
|
28
|
+
|
29
|
+
describe "#which" do
|
30
|
+
def self.test_which(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: nil, others: [], directory: false, &block)
|
31
|
+
it description do
|
32
|
+
# stub the ENV['PATH']
|
33
|
+
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
34
|
+
expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
|
35
|
+
|
36
|
+
# most files should not be found
|
37
|
+
allow(File).to receive(:executable?).and_return(false)
|
38
|
+
allow(File).to receive(:directory?).and_return(false)
|
39
|
+
|
40
|
+
# stub the expectation
|
41
|
+
expect(File).to receive(:executable?).with(finds).and_return(true) if finds
|
42
|
+
|
43
|
+
# if the file we find is a directory
|
44
|
+
expect(File).to receive(:directory?).with(finds).and_return(true) if finds && directory
|
45
|
+
|
46
|
+
# allow for stubbing other paths to exist that we should not find
|
47
|
+
others.each do |other|
|
48
|
+
allow(File).to receive(:executable?).with(other).and_return(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
# setup the actual expectation on the return value
|
52
|
+
if finds && !directory
|
53
|
+
expect(test.which(*args, &block)).to eql(finds)
|
54
|
+
else
|
55
|
+
expect(test.which(*args, &block)).to eql(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "simple usage" do
|
61
|
+
test_which("returns false when it does not find anything", "foo1")
|
62
|
+
|
63
|
+
["/dir1", "/dir2" ].each do |dir|
|
64
|
+
test_which("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: "#{dir}/foo1")
|
65
|
+
end
|
66
|
+
|
67
|
+
test_which("does not find an executable directory", "foo1", finds: "/dir1/foo1", directory: true)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with an array of args" do
|
71
|
+
test_which("finds the first arg", "foo1", "foo2", finds: "/dir2/foo1")
|
72
|
+
|
73
|
+
test_which("finds the second arg", "foo1", "foo2", finds: "/dir2/foo2")
|
74
|
+
|
75
|
+
test_which("finds the first arg when there's both", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ])
|
76
|
+
|
77
|
+
test_which("and the directory order can be reversed", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir2/foo2" ])
|
78
|
+
|
79
|
+
test_which("or be the same", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir1/foo2" ])
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with a block" do
|
83
|
+
test_which("doesn't find it if its false", "foo1", others: [ "/dir1/foo1" ]) do |f|
|
84
|
+
false
|
85
|
+
end
|
86
|
+
|
87
|
+
test_which("finds it if its true", "foo1", finds: "/dir1/foo1") do |f|
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
test_which("passes in the filename as the arg", "foo1", finds: "/dir1/foo1") do |f|
|
92
|
+
raise "bad arg to block" unless f == "/dir1/foo1"
|
93
|
+
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f|
|
98
|
+
raise "bad arg to block" unless ["/dir2/foo1", "/dir1/foo2"].include?(f)
|
99
|
+
|
100
|
+
true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "nil path" do
|
105
|
+
test_which("returns false when it does not find anything", "foo1", path: nil)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#where" do
|
110
|
+
def self.test_where(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: [], others: [], &block)
|
111
|
+
it description do
|
112
|
+
# stub the ENV['PATH']
|
113
|
+
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
114
|
+
expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
|
115
|
+
|
116
|
+
# most files should not be found
|
117
|
+
allow(File).to receive(:executable?).and_return(false)
|
118
|
+
allow(File).to receive(:directory?).and_return(false)
|
119
|
+
|
120
|
+
# allow for stubbing other paths to exist that we should not return
|
121
|
+
others.each do |other|
|
122
|
+
allow(File).to receive(:executable?).with(other).and_return(true)
|
123
|
+
end
|
124
|
+
|
125
|
+
# stub the expectation
|
126
|
+
finds.each do |path|
|
127
|
+
expect(File).to receive(:executable?).with(path).and_return(true)
|
128
|
+
end
|
129
|
+
|
130
|
+
# setup the actual expectation on the return value
|
131
|
+
expect(test.where(*args, &block)).to eql(finds)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "simple usage" do
|
136
|
+
test_where("returns empty array when it doesn't find anything", "foo1")
|
137
|
+
|
138
|
+
["/dir1", "/dir2" ].each do |dir|
|
139
|
+
test_where("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: [ "#{dir}/foo1" ])
|
140
|
+
end
|
141
|
+
|
142
|
+
test_where("finds `foo1` in all directories", "foo1", finds: [ "/dir1/foo1", "/dir2/foo1" ])
|
143
|
+
end
|
144
|
+
|
145
|
+
context "with an array of args" do
|
146
|
+
test_where("finds the first arg", "foo1", "foo2", finds: [ "/dir2/foo1" ])
|
147
|
+
|
148
|
+
test_where("finds the second arg", "foo1", "foo2", finds: [ "/dir2/foo2" ])
|
149
|
+
|
150
|
+
test_where("finds foo1 before foo2 if the dirs are reversed", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir2/foo2" ])
|
151
|
+
|
152
|
+
test_where("finds them both in the same directory", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir1/foo2" ])
|
153
|
+
|
154
|
+
test_where("finds foo2 first if they're reversed", "foo2", "foo1", finds: [ "/dir1/foo2", "/dir1/foo1" ])
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with a block do" do
|
158
|
+
test_where("finds foo1 and foo2 if they exist and the block is true", "foo1", "foo2", finds: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
159
|
+
true
|
160
|
+
end
|
161
|
+
|
162
|
+
test_where("does not finds foo1 and foo2 if they exist and the block is false", "foo1", "foo2", others: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
163
|
+
false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with a nil path" do
|
168
|
+
test_where("returns empty array when it doesn't find anything", "foo1", path: nil)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -1,84 +1,84 @@
|
|
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
|
-
WINDOWS_BOOL_HELPERS = %i{windows_server_core? windows_server? windows_workstation?}.freeze
|
22
|
-
|
23
|
-
def windows_reports_true_for(*args)
|
24
|
-
args.each do |method|
|
25
|
-
it "reports true for #{method}" do
|
26
|
-
expect(described_class.send(method, node)).to be true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
(WINDOWS_BOOL_HELPERS - args).each do |method|
|
30
|
-
it "reports false for #{method}" do
|
31
|
-
expect(described_class.send(method, node)).to be false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
RSpec.describe ChefUtils::DSL::Windows do
|
37
|
-
( HELPER_MODULES - [ described_class ] ).each do |klass|
|
38
|
-
it "does not have methods that collide with #{klass}" do
|
39
|
-
expect((klass.methods - Module.methods) & WINDOWS_HELPERS).to be_empty
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
WINDOWS_HELPERS.each do |helper|
|
44
|
-
it "has the #{helper} in the ChefUtils module" do
|
45
|
-
expect(ChefUtils).to respond_to(helper)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "windows boolean helpers" do
|
50
|
-
context "on Windows Server Core" do
|
51
|
-
let(:node) { { "kernel" => { "server_core" => true } } }
|
52
|
-
|
53
|
-
windows_reports_true_for(:windows_server_core?)
|
54
|
-
end
|
55
|
-
|
56
|
-
context "on Windows Workstation" do
|
57
|
-
let(:node) { { "kernel" => { "product_type" => "Workstation" } } }
|
58
|
-
|
59
|
-
windows_reports_true_for(:windows_workstation?)
|
60
|
-
end
|
61
|
-
|
62
|
-
context "on Windows Server" do
|
63
|
-
let(:node) { { "kernel" => { "product_type" => "Server" } } }
|
64
|
-
|
65
|
-
windows_reports_true_for(:windows_server?)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "#windows_nt_version on Windows Server 2012 R2" do
|
70
|
-
let(:node) { { "os_version" => "6.3.9600" } }
|
71
|
-
it "it returns a ChefUtils::VersionString object with 6.3.9600" do
|
72
|
-
expect(described_class.send(:windows_nt_version, node)).to eq "6.3.9600"
|
73
|
-
expect(described_class.send(:windows_nt_version, node)).to be_a_kind_of ChefUtils::VersionString
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "#powershell_version on Windows Server 2012 R2" do
|
78
|
-
let(:node) { { "languages" => { "powershell" => { "version" => "4.0" } } } }
|
79
|
-
it "it returns a ChefUtils::VersionString object with 4.0" do
|
80
|
-
expect(described_class.send(:powershell_version, node)).to eq "4.0"
|
81
|
-
expect(described_class.send(:powershell_version, node)).to be_a_kind_of ChefUtils::VersionString
|
82
|
-
end
|
83
|
-
end
|
84
|
-
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
|
+
WINDOWS_BOOL_HELPERS = %i{windows_server_core? windows_server? windows_workstation?}.freeze
|
22
|
+
|
23
|
+
def windows_reports_true_for(*args)
|
24
|
+
args.each do |method|
|
25
|
+
it "reports true for #{method}" do
|
26
|
+
expect(described_class.send(method, node)).to be true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
(WINDOWS_BOOL_HELPERS - args).each do |method|
|
30
|
+
it "reports false for #{method}" do
|
31
|
+
expect(described_class.send(method, node)).to be false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec.describe ChefUtils::DSL::Windows do
|
37
|
+
( HELPER_MODULES - [ described_class ] ).each do |klass|
|
38
|
+
it "does not have methods that collide with #{klass}" do
|
39
|
+
expect((klass.methods - Module.methods) & WINDOWS_HELPERS).to be_empty
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
WINDOWS_HELPERS.each do |helper|
|
44
|
+
it "has the #{helper} in the ChefUtils module" do
|
45
|
+
expect(ChefUtils).to respond_to(helper)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "windows boolean helpers" do
|
50
|
+
context "on Windows Server Core" do
|
51
|
+
let(:node) { { "kernel" => { "server_core" => true } } }
|
52
|
+
|
53
|
+
windows_reports_true_for(:windows_server_core?)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "on Windows Workstation" do
|
57
|
+
let(:node) { { "kernel" => { "product_type" => "Workstation" } } }
|
58
|
+
|
59
|
+
windows_reports_true_for(:windows_workstation?)
|
60
|
+
end
|
61
|
+
|
62
|
+
context "on Windows Server" do
|
63
|
+
let(:node) { { "kernel" => { "product_type" => "Server" } } }
|
64
|
+
|
65
|
+
windows_reports_true_for(:windows_server?)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "#windows_nt_version on Windows Server 2012 R2" do
|
70
|
+
let(:node) { { "os_version" => "6.3.9600" } }
|
71
|
+
it "it returns a ChefUtils::VersionString object with 6.3.9600" do
|
72
|
+
expect(described_class.send(:windows_nt_version, node)).to eq "6.3.9600"
|
73
|
+
expect(described_class.send(:windows_nt_version, node)).to be_a_kind_of ChefUtils::VersionString
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "#powershell_version on Windows Server 2012 R2" do
|
78
|
+
let(:node) { { "languages" => { "powershell" => { "version" => "4.0" } } } }
|
79
|
+
it "it returns a ChefUtils::VersionString object with 4.0" do
|
80
|
+
expect(described_class.send(:powershell_version, node)).to eq "4.0"
|
81
|
+
expect(described_class.send(:powershell_version, node)).to be_a_kind_of ChefUtils::VersionString
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/unit/mash_spec.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Matthew Kent (<mkent@magoazul.com>)
|
4
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
|
22
|
-
RSpec.describe ChefUtils::Mash do
|
23
|
-
it "should duplicate a simple key/value mash to a new mash" do
|
24
|
-
data = { x: "one", y: "two", z: "three" }
|
25
|
-
@orig = ChefUtils::Mash.new(data)
|
26
|
-
@copy = @orig.dup
|
27
|
-
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
28
|
-
@copy[:x] = "four"
|
29
|
-
expect(@orig[:x]).to eq("one")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should duplicate a mash with an array to a new mash" do
|
33
|
-
data = { x: "one", y: "two", z: [1, 2, 3] }
|
34
|
-
@orig = ChefUtils::Mash.new(data)
|
35
|
-
@copy = @orig.dup
|
36
|
-
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
37
|
-
@copy[:z] << 4
|
38
|
-
expect(@orig[:z]).to eq([1, 2, 3])
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should duplicate a nested mash to a new mash" do
|
42
|
-
data = { x: "one", y: "two", z: ChefUtils::Mash.new({ a: [1, 2, 3] }) }
|
43
|
-
@orig = ChefUtils::Mash.new(data)
|
44
|
-
@copy = @orig.dup
|
45
|
-
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
46
|
-
@copy[:z][:a] << 4
|
47
|
-
expect(@orig[:z][:a]).to eq([1, 2, 3])
|
48
|
-
end
|
49
|
-
|
50
|
-
# add more!
|
51
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Author:: Matthew Kent (<mkent@magoazul.com>)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require "spec_helper"
|
21
|
+
|
22
|
+
RSpec.describe ChefUtils::Mash do
|
23
|
+
it "should duplicate a simple key/value mash to a new mash" do
|
24
|
+
data = { x: "one", y: "two", z: "three" }
|
25
|
+
@orig = ChefUtils::Mash.new(data)
|
26
|
+
@copy = @orig.dup
|
27
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
28
|
+
@copy[:x] = "four"
|
29
|
+
expect(@orig[:x]).to eq("one")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should duplicate a mash with an array to a new mash" do
|
33
|
+
data = { x: "one", y: "two", z: [1, 2, 3] }
|
34
|
+
@orig = ChefUtils::Mash.new(data)
|
35
|
+
@copy = @orig.dup
|
36
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
37
|
+
@copy[:z] << 4
|
38
|
+
expect(@orig[:z]).to eq([1, 2, 3])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should duplicate a nested mash to a new mash" do
|
42
|
+
data = { x: "one", y: "two", z: ChefUtils::Mash.new({ a: [1, 2, 3] }) }
|
43
|
+
@orig = ChefUtils::Mash.new(data)
|
44
|
+
@copy = @orig.dup
|
45
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
46
|
+
@copy[:z][:a] << 4
|
47
|
+
expect(@orig[:z][:a]).to eq([1, 2, 3])
|
48
|
+
end
|
49
|
+
|
50
|
+
# add more!
|
51
|
+
end
|