chef-utils 0.0.1 → 15.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/chef-utils.gemspec +11 -3
- data/lib/chef-utils.rb +43 -0
- data/lib/chef-utils/dsl/architecture.rb +117 -0
- data/lib/chef-utils/dsl/introspection.rb +93 -0
- data/lib/chef-utils/dsl/os.rb +55 -0
- data/lib/chef-utils/dsl/path_sanity.rb +58 -0
- data/lib/chef-utils/dsl/platform.rb +339 -0
- data/lib/chef-utils/dsl/platform_family.rb +314 -0
- data/lib/chef-utils/dsl/service.rb +91 -0
- data/lib/chef-utils/dsl/train_helpers.rb +63 -0
- data/lib/chef-utils/dsl/which.rb +118 -0
- data/lib/chef-utils/internal.rb +77 -0
- data/lib/chef-utils/mash.rb +239 -0
- data/lib/chef-utils/version.rb +1 -1
- data/spec/spec_helper.rb +93 -0
- data/spec/unit/dsl/architecture_spec.rb +139 -0
- data/spec/unit/dsl/dsl_spec.rb +33 -0
- data/spec/unit/dsl/introspection_spec.rb +168 -0
- data/spec/unit/dsl/os_spec.rb +174 -0
- data/spec/unit/dsl/path_sanity_spec.rb +85 -0
- data/spec/unit/dsl/platform_family_spec.rb +222 -0
- data/spec/unit/dsl/platform_spec.rb +234 -0
- data/spec/unit/dsl/service_spec.rb +116 -0
- data/spec/unit/dsl/which_spec.rb +168 -0
- data/spec/unit/mash_spec.rb +50 -0
- metadata +35 -7
@@ -0,0 +1,116 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2018-2019, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
RSpec.describe ChefUtils::DSL::Service do
|
21
|
+
class ServiceTestClass
|
22
|
+
include ChefUtils::DSL::Service
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:test_instance) { ServiceTestClass.new }
|
26
|
+
|
27
|
+
context "#debianrcd?" do
|
28
|
+
it "is true if the binary is installed" do
|
29
|
+
expect(File).to receive(:exist?).with("/usr/sbin/update-rc.d").and_return(true)
|
30
|
+
expect(test_instance.debianrcd?).to be true
|
31
|
+
end
|
32
|
+
it "is false if the binary is not installed" do
|
33
|
+
expect(File).to receive(:exist?).with("/usr/sbin/update-rc.d").and_return(false)
|
34
|
+
expect(test_instance.debianrcd?).to be false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "#invokercd?" do
|
39
|
+
it "is true if the binary is installed" do
|
40
|
+
expect(File).to receive(:exist?).with("/usr/sbin/invoke-rc.d").and_return(true)
|
41
|
+
expect(test_instance.invokercd?).to be true
|
42
|
+
end
|
43
|
+
it "is false if the binary is not installed" do
|
44
|
+
expect(File).to receive(:exist?).with("/usr/sbin/invoke-rc.d").and_return(false)
|
45
|
+
expect(test_instance.invokercd?).to be false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#upstart?" do
|
50
|
+
it "is true if the binary is installed" do
|
51
|
+
expect(File).to receive(:exist?).with("/sbin/initctl").and_return(true)
|
52
|
+
expect(test_instance.upstart?).to be true
|
53
|
+
end
|
54
|
+
it "is false if the binary is not installed" do
|
55
|
+
expect(File).to receive(:exist?).with("/sbin/initctl").and_return(false)
|
56
|
+
expect(test_instance.upstart?).to be false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#insserv?" do
|
61
|
+
it "is true if the binary is installed" do
|
62
|
+
expect(File).to receive(:exist?).with("/sbin/insserv").and_return(true)
|
63
|
+
expect(test_instance.insserv?).to be true
|
64
|
+
end
|
65
|
+
it "is false if the binary is not installed" do
|
66
|
+
expect(File).to receive(:exist?).with("/sbin/insserv").and_return(false)
|
67
|
+
expect(test_instance.insserv?).to be false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "#redhatrcd?" do
|
72
|
+
it "is true if the binary is installed" do
|
73
|
+
expect(File).to receive(:exist?).with("/sbin/chkconfig").and_return(true)
|
74
|
+
expect(test_instance.redhatrcd?).to be true
|
75
|
+
end
|
76
|
+
it "is false if the binary is not installed" do
|
77
|
+
expect(File).to receive(:exist?).with("/sbin/chkconfig").and_return(false)
|
78
|
+
expect(test_instance.redhatrcd?).to be false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "#service_script_exist?" do
|
83
|
+
it "is true if the type is :initd and /etc/init.d script exists" do
|
84
|
+
expect(File).to receive(:exist?).with("/etc/init.d/example").and_return(true)
|
85
|
+
expect(test_instance.service_script_exist?(:initd, "example")).to be true
|
86
|
+
end
|
87
|
+
it "is false if the type is :initd and /etc/init.d script does not exist" do
|
88
|
+
expect(File).to receive(:exist?).with("/etc/init.d/example").and_return(false)
|
89
|
+
expect(test_instance.service_script_exist?(:initd, "example")).to be false
|
90
|
+
end
|
91
|
+
it "is true if the type is :upstart and /etc/init script exists" do
|
92
|
+
expect(File).to receive(:exist?).with("/etc/init/example.conf").and_return(true)
|
93
|
+
expect(test_instance.service_script_exist?(:upstart, "example")).to be true
|
94
|
+
end
|
95
|
+
it "is false if the type is :upstart and /etc/init script does not exist" do
|
96
|
+
expect(File).to receive(:exist?).with("/etc/init/example.conf").and_return(false)
|
97
|
+
expect(test_instance.service_script_exist?(:upstart, "example")).to be false
|
98
|
+
end
|
99
|
+
it "is true if the type is :xinetd and /etc/xinetd.d script exists" do
|
100
|
+
expect(File).to receive(:exist?).with("/etc/xinetd.d/example").and_return(true)
|
101
|
+
expect(test_instance.service_script_exist?(:xinetd, "example")).to be true
|
102
|
+
end
|
103
|
+
it "is false if the type is :xinetd and /etc/xinetd.d script does not exist" do
|
104
|
+
expect(File).to receive(:exist?).with("/etc/xinetd.d/example").and_return(false)
|
105
|
+
expect(test_instance.service_script_exist?(:xinetd, "example")).to be false
|
106
|
+
end
|
107
|
+
it "is true if the type is :etc_rcd and /etc/rc.d script exists" do
|
108
|
+
expect(File).to receive(:exist?).with("/etc/rc.d/example").and_return(true)
|
109
|
+
expect(test_instance.service_script_exist?(:etc_rcd, "example")).to be true
|
110
|
+
end
|
111
|
+
it "is false if the type is :etc_rcd and /etc/rc.d script does not exist" do
|
112
|
+
expect(File).to receive(:exist?).with("/etc/rc.d/example").and_return(false)
|
113
|
+
expect(test_instance.service_script_exist?(:etc_rcd, "example")).to be false
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2018-2019, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
RSpec.describe ChefUtils::DSL::Which do
|
21
|
+
|
22
|
+
class WhichTestClass
|
23
|
+
include ChefUtils::DSL::Which
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:test) { WhichTestClass.new }
|
27
|
+
|
28
|
+
describe "#which" do
|
29
|
+
def self.test_which(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: nil, others: [], directory: false, &block)
|
30
|
+
it description do
|
31
|
+
# stub the ENV['PATH']
|
32
|
+
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
33
|
+
|
34
|
+
# most files should not be found
|
35
|
+
allow(File).to receive(:executable?).and_return(false)
|
36
|
+
allow(File).to receive(:directory?).and_return(false)
|
37
|
+
|
38
|
+
# stub the expectation
|
39
|
+
expect(File).to receive(:executable?).with(finds).and_return(true) if finds
|
40
|
+
|
41
|
+
# if the file we find is a directory
|
42
|
+
expect(File).to receive(:directory?).with(finds).and_return(true) if finds && directory
|
43
|
+
|
44
|
+
# allow for stubbing other paths to exist that we should not find
|
45
|
+
others.each do |other|
|
46
|
+
allow(File).to receive(:executable?).with(other).and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
# setup the actual expectation on the return value
|
50
|
+
if finds && !directory
|
51
|
+
expect(test.which(*args, &block)).to eql(finds)
|
52
|
+
else
|
53
|
+
expect(test.which(*args, &block)).to eql(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "simple usage" do
|
59
|
+
test_which("returns false when it does not find anything", "foo1")
|
60
|
+
|
61
|
+
["/dir1", "/dir2" ].each do |dir|
|
62
|
+
test_which("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: "#{dir}/foo1")
|
63
|
+
end
|
64
|
+
|
65
|
+
test_which("does not find an executable directory", "foo1", finds: "/dir1/foo1", directory: true)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with an array of args" do
|
69
|
+
test_which("finds the first arg", "foo1", "foo2", finds: "/dir2/foo1")
|
70
|
+
|
71
|
+
test_which("finds the second arg", "foo1", "foo2", finds: "/dir2/foo2")
|
72
|
+
|
73
|
+
test_which("finds the first arg when there's both", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ])
|
74
|
+
|
75
|
+
test_which("and the directory order can be reversed", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir2/foo2" ])
|
76
|
+
|
77
|
+
test_which("or be the same", "foo1", "foo2", finds: "/dir1/foo1", others: [ "/dir1/foo2" ])
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with a block" do
|
81
|
+
test_which("doesnt find it if its false", "foo1", others: [ "/dir1/foo1" ]) do |f|
|
82
|
+
false
|
83
|
+
end
|
84
|
+
|
85
|
+
test_which("finds it if its true", "foo1", finds: "/dir1/foo1") do |f|
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
test_which("passes in the filename as the arg", "foo1", finds: "/dir1/foo1") do |f|
|
90
|
+
raise "bad arg to block" unless f == "/dir1/foo1"
|
91
|
+
|
92
|
+
true
|
93
|
+
end
|
94
|
+
|
95
|
+
test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f|
|
96
|
+
raise "bad arg to block" unless f == "/dir2/foo1" || f == "/dir1/foo2"
|
97
|
+
|
98
|
+
true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "nil path" do
|
103
|
+
test_which("returns false when it does not find anything", "foo1", path: nil)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#where" do
|
108
|
+
def self.test_where(description, *args, path: ["/dir1", "/dir2" ].join(File::PATH_SEPARATOR), finds: [], others: [], &block)
|
109
|
+
it description do
|
110
|
+
# stub the ENV['PATH']
|
111
|
+
expect(ENV).to receive(:[]).with("PATH").and_return(path)
|
112
|
+
|
113
|
+
# most files should not be found
|
114
|
+
allow(File).to receive(:executable?).and_return(false)
|
115
|
+
allow(File).to receive(:directory?).and_return(false)
|
116
|
+
|
117
|
+
# allow for stubbing other paths to exist that we should not return
|
118
|
+
others.each do |other|
|
119
|
+
allow(File).to receive(:executable?).with(other).and_return(true)
|
120
|
+
end
|
121
|
+
|
122
|
+
# stub the expectation
|
123
|
+
finds.each do |path|
|
124
|
+
expect(File).to receive(:executable?).with(path).and_return(true)
|
125
|
+
end
|
126
|
+
|
127
|
+
# setup the actual expectation on the return value
|
128
|
+
expect(test.where(*args, &block)).to eql(finds)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "simple usage" do
|
133
|
+
test_where("returns empty array when it doesn't find anything", "foo1")
|
134
|
+
|
135
|
+
["/dir1", "/dir2" ].each do |dir|
|
136
|
+
test_where("finds `foo1` in #{dir} when it is stubbed", "foo1", finds: [ "#{dir}/foo1" ])
|
137
|
+
end
|
138
|
+
|
139
|
+
test_where("finds `foo1` in all directories", "foo1", finds: [ "/dir1/foo1", "/dir2/foo1" ])
|
140
|
+
end
|
141
|
+
|
142
|
+
context "with an array of args" do
|
143
|
+
test_where("finds the first arg", "foo1", "foo2", finds: [ "/dir2/foo1" ])
|
144
|
+
|
145
|
+
test_where("finds the second arg", "foo1", "foo2", finds: [ "/dir2/foo2" ])
|
146
|
+
|
147
|
+
test_where("finds foo1 before foo2 if the dirs are reversed", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir2/foo2" ])
|
148
|
+
|
149
|
+
test_where("finds them both in the same directory", "foo1", "foo2", finds: [ "/dir1/foo1", "/dir1/foo2" ])
|
150
|
+
|
151
|
+
test_where("finds foo2 first if they're reversed", "foo2", "foo1", finds: [ "/dir1/foo2", "/dir1/foo1" ])
|
152
|
+
end
|
153
|
+
|
154
|
+
context "with a block do" do
|
155
|
+
test_where("finds foo1 and foo2 if they exist and the block is true", "foo1", "foo2", finds: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
156
|
+
true
|
157
|
+
end
|
158
|
+
|
159
|
+
test_where("does not finds foo1 and foo2 if they exist and the block is false", "foo1", "foo2", others: [ "/dir1/foo2", "/dir2/foo2" ]) do
|
160
|
+
false
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "with a nil path" do
|
165
|
+
test_where("returns empty array when it doesn't find anything", "foo1", path: nil)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matthew Kent (<mkent@magoazul.com>)
|
3
|
+
# Copyright:: Copyright 2011-2016, 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::Mash do
|
22
|
+
it "should duplicate a simple key/value mash to a new mash" do
|
23
|
+
data = { x: "one", y: "two", z: "three" }
|
24
|
+
@orig = ChefUtils::Mash.new(data)
|
25
|
+
@copy = @orig.dup
|
26
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
27
|
+
@copy[:x] = "four"
|
28
|
+
expect(@orig[:x]).to eq("one")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should duplicate a mash with an array to a new mash" do
|
32
|
+
data = { x: "one", y: "two", z: [1, 2, 3] }
|
33
|
+
@orig = ChefUtils::Mash.new(data)
|
34
|
+
@copy = @orig.dup
|
35
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
36
|
+
@copy[:z] << 4
|
37
|
+
expect(@orig[:z]).to eq([1, 2, 3])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should duplicate a nested mash to a new mash" do
|
41
|
+
data = { x: "one", y: "two", z: ChefUtils::Mash.new({ a: [1, 2, 3] }) }
|
42
|
+
@orig = ChefUtils::Mash.new(data)
|
43
|
+
@copy = @orig.dup
|
44
|
+
expect(@copy.to_hash).to eq(ChefUtils::Mash.new(data).to_hash)
|
45
|
+
@copy[:z][:a] << 4
|
46
|
+
expect(@orig[:z][:a]).to eq([1, 2, 3])
|
47
|
+
end
|
48
|
+
|
49
|
+
# add more!
|
50
|
+
end
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 15.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Chef Software, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
15
|
-
-
|
15
|
+
- oss@chef.io
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
@@ -20,11 +20,39 @@ files:
|
|
20
20
|
- LICENSE
|
21
21
|
- Rakefile
|
22
22
|
- chef-utils.gemspec
|
23
|
+
- lib/chef-utils.rb
|
24
|
+
- lib/chef-utils/dsl/architecture.rb
|
25
|
+
- lib/chef-utils/dsl/introspection.rb
|
26
|
+
- lib/chef-utils/dsl/os.rb
|
27
|
+
- lib/chef-utils/dsl/path_sanity.rb
|
28
|
+
- lib/chef-utils/dsl/platform.rb
|
29
|
+
- lib/chef-utils/dsl/platform_family.rb
|
30
|
+
- lib/chef-utils/dsl/service.rb
|
31
|
+
- lib/chef-utils/dsl/train_helpers.rb
|
32
|
+
- lib/chef-utils/dsl/which.rb
|
33
|
+
- lib/chef-utils/internal.rb
|
34
|
+
- lib/chef-utils/mash.rb
|
23
35
|
- lib/chef-utils/version.rb
|
24
|
-
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/unit/dsl/architecture_spec.rb
|
38
|
+
- spec/unit/dsl/dsl_spec.rb
|
39
|
+
- spec/unit/dsl/introspection_spec.rb
|
40
|
+
- spec/unit/dsl/os_spec.rb
|
41
|
+
- spec/unit/dsl/path_sanity_spec.rb
|
42
|
+
- spec/unit/dsl/platform_family_spec.rb
|
43
|
+
- spec/unit/dsl/platform_spec.rb
|
44
|
+
- spec/unit/dsl/service_spec.rb
|
45
|
+
- spec/unit/dsl/which_spec.rb
|
46
|
+
- spec/unit/mash_spec.rb
|
47
|
+
homepage: https://github.com/chef/chef/tree/master/chef-utils
|
25
48
|
licenses:
|
26
49
|
- Apache-2.0
|
27
|
-
metadata:
|
50
|
+
metadata:
|
51
|
+
bug_tracker_uri: https://github.com/chef/chef/issues
|
52
|
+
changelog_uri: https://github.com/chef/chef/CHANGELOG.md
|
53
|
+
documentation_uri: https://github.com/chef/chef/tree/master/chef-utils/README.md
|
54
|
+
homepage_uri: https://github.com/chef/chef/tree/master/chef-utils
|
55
|
+
source_code_uri: https://github.com/chef/chef/tree/master/chef-utils
|
28
56
|
post_install_message:
|
29
57
|
rdoc_options: []
|
30
58
|
require_paths:
|
@@ -40,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
68
|
- !ruby/object:Gem::Version
|
41
69
|
version: '0'
|
42
70
|
requirements: []
|
43
|
-
rubygems_version: 3.0.
|
71
|
+
rubygems_version: 3.0.3
|
44
72
|
signing_key:
|
45
73
|
specification_version: 4
|
46
74
|
summary: Basic utility functions for Core Chef development
|