chef-cli 1.0.11 → 1.0.13
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/lib/chef-cli/cli.rb +54 -1
- data/lib/chef-cli/helpers.rb +3 -3
- data/lib/chef-cli/policyfile/git_lock_fetcher.rb +1 -1
- data/lib/chef-cli/version.rb +1 -1
- data/spec/unit/cli_spec.rb +113 -42
- data/spec/unit/policyfile/git_lock_fetcher_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5f6126a4c90780ea0e12bfb21478a40bce4d2432735b5ce2e36c6114414d06
|
4
|
+
data.tar.gz: beed8e750ba8df274e82be2aa11238a07d55968d1686b7c1f0393c303639dc5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82d425973ce0b4e17c55a2f536773a5c9ad40ba50bdcd2b537b64d04462d4b9d970d27d642574f86529839549235007778b8c77608dfb19352b1fdef79c11e0d
|
7
|
+
data.tar.gz: 041f50bcdc2cbaab8efdc1f51b53d279d6cf1b11a72deac5124885ad1e8acf52fb4ab052ff9dade90b60d2dcae7e88f7371bec74184504ff23655028bc0da13c
|
data/lib/chef-cli/cli.rb
CHANGED
@@ -96,11 +96,30 @@ module ChefCLI
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def show_version
|
99
|
+
if omnibus_install?
|
100
|
+
show_version_via_version_manifest
|
101
|
+
else
|
102
|
+
show_version_via_shell_out
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def show_version_via_version_manifest
|
107
|
+
msg("#{ChefCLI::Dist::PRODUCT} version: #{manifest_field("build_version")}")
|
108
|
+
{ "#{ChefCLI::Dist::INFRA_CLIENT_PRODUCT}": "chef",
|
109
|
+
"#{ChefCLI::Dist::INSPEC_PRODUCT}": "#{ChefCLI::Dist::INSPEC_CLI}",
|
110
|
+
"Chef CLI": "chef-cli",
|
111
|
+
"Test Kitchen": "test-kitchen",
|
112
|
+
"Cookstyle": "cookstyle",
|
113
|
+
}.each do |name, gem|
|
114
|
+
msg("#{name} version: #{gem_version(gem)}")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def show_version_via_shell_out
|
99
119
|
msg("#{ChefCLI::Dist::PRODUCT} version: #{ChefCLI::VERSION}")
|
100
120
|
{ "#{ChefCLI::Dist::INFRA_CLIENT_PRODUCT}": "#{ChefCLI::Dist::INFRA_CLIENT_CLI}",
|
101
121
|
"#{ChefCLI::Dist::INSPEC_PRODUCT}": "#{ChefCLI::Dist::INSPEC_CLI}",
|
102
122
|
"Test Kitchen": "kitchen",
|
103
|
-
"Foodcritic": "foodcritic",
|
104
123
|
"Cookstyle": "cookstyle",
|
105
124
|
}.each do |name, cli|
|
106
125
|
result = Bundler.with_clean_env { shell_out("#{cli} --version") }
|
@@ -155,6 +174,40 @@ module ChefCLI
|
|
155
174
|
|
156
175
|
private
|
157
176
|
|
177
|
+
def manifest_field(field)
|
178
|
+
if manifest_hash[field]
|
179
|
+
manifest_hash[field]
|
180
|
+
else
|
181
|
+
"unknown"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def gem_version(name)
|
186
|
+
if gem_manifest_hash[name].is_a?(Array)
|
187
|
+
gem_manifest_hash[name].first
|
188
|
+
else
|
189
|
+
"unknown"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def manifest_hash
|
194
|
+
require "json"
|
195
|
+
@manifest_hash ||= JSON.parse(read_version_manifest_json)
|
196
|
+
end
|
197
|
+
|
198
|
+
def gem_manifest_hash
|
199
|
+
require "json"
|
200
|
+
@gem_manifest_hash ||= JSON.parse(read_gem_version_manifest_json)
|
201
|
+
end
|
202
|
+
|
203
|
+
def read_version_manifest_json
|
204
|
+
File.read(File.join(omnibus_root, "version-manifest.json"))
|
205
|
+
end
|
206
|
+
|
207
|
+
def read_gem_version_manifest_json
|
208
|
+
File.read(File.join(omnibus_root, "gem-version-manifest.json"))
|
209
|
+
end
|
210
|
+
|
158
211
|
def normalized_exit_code(maybe_integer)
|
159
212
|
if maybe_integer.is_a?(Integer) && (0..255).cover?(maybe_integer)
|
160
213
|
maybe_integer
|
data/lib/chef-cli/helpers.rb
CHANGED
@@ -51,9 +51,9 @@ module ChefCLI
|
|
51
51
|
# Locates the omnibus directories
|
52
52
|
#
|
53
53
|
def omnibus_install?
|
54
|
-
# We also
|
55
|
-
# includes the version manifest that omnibus packages ship with.
|
56
|
-
# out of a gem - so not as an 'omnibus install'
|
54
|
+
# We also check if the location we're running from (omnibus_root is relative to currently-running ruby)
|
55
|
+
# includes the version manifest that omnibus packages ship with. If it doesn't, then we're running locally
|
56
|
+
# or out of a gem - so not as an 'omnibus install'
|
57
57
|
File.exist?(expected_omnibus_root) && File.exist?(File.join(expected_omnibus_root, "version-manifest.json"))
|
58
58
|
end
|
59
59
|
|
@@ -195,7 +195,7 @@ module ChefCLI
|
|
195
195
|
#
|
196
196
|
# @return [String] Content of specified file for a given revision.
|
197
197
|
def show_file(version, file)
|
198
|
-
git("show #{version}:#{file}", cwd: cache_path)
|
198
|
+
git("show #{version}:#{file}", cwd: cache_path.to_s)
|
199
199
|
end
|
200
200
|
|
201
201
|
# COPYPASTA from CookbookOmnifetch
|
data/lib/chef-cli/version.rb
CHANGED
data/spec/unit/cli_spec.rb
CHANGED
@@ -124,53 +124,124 @@ describe ChefCLI::CLI do
|
|
124
124
|
context "given -v" do
|
125
125
|
let(:argv) { %w{-v} }
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
127
|
+
context "#via_version_manifest" do
|
128
|
+
let(:mocked_version_manifest_json) do
|
129
|
+
<<~E
|
130
|
+
{
|
131
|
+
"manifest_format": 2,
|
132
|
+
"build_version": "d.e.v"
|
133
|
+
}
|
134
|
+
E
|
135
|
+
end
|
136
|
+
|
137
|
+
let(:mocked_gem_version_manifest_json) do
|
138
|
+
<<~E
|
139
|
+
{
|
140
|
+
"chef-cli": [
|
141
|
+
"0.0.1"
|
142
|
+
],
|
143
|
+
"chef": [
|
144
|
+
"0.0.2"
|
145
|
+
],
|
146
|
+
"inspec": [
|
147
|
+
"0.0.3"
|
148
|
+
],
|
149
|
+
"test-kitchen": [
|
150
|
+
"0.0.4"
|
151
|
+
],
|
152
|
+
"cookstyle": [
|
153
|
+
"0.0.6"
|
154
|
+
]
|
155
|
+
}
|
156
|
+
E
|
157
|
+
end
|
158
|
+
|
159
|
+
# rubocop:disable Layout/TrailingWhitespace
|
160
|
+
let(:full_table_with_version_message) do
|
161
|
+
<<~E
|
162
|
+
Chef Workstation version: d.e.v
|
163
|
+
Chef Infra Client version: 0.0.2
|
164
|
+
Chef InSpec version: 0.0.3
|
165
|
+
Chef CLI version: 0.0.1
|
166
|
+
Test Kitchen version: 0.0.4
|
167
|
+
Cookstyle version: 0.0.6
|
168
|
+
E
|
169
|
+
end
|
170
|
+
|
171
|
+
let(:full_table_with_unknown_version_message) do
|
172
|
+
<<~E
|
173
|
+
Chef Workstation version: unknown
|
174
|
+
Chef Infra Client version: unknown
|
175
|
+
Chef InSpec version: unknown
|
176
|
+
Chef CLI version: unknown
|
177
|
+
Test Kitchen version: unknown
|
178
|
+
Cookstyle version: unknown
|
179
|
+
E
|
180
|
+
end
|
181
|
+
|
182
|
+
before do
|
183
|
+
allow(cli).to receive(:omnibus_install?).and_return true
|
184
|
+
allow(cli).to receive(:read_version_manifest_json).and_return(mocked_version_manifest_json)
|
185
|
+
allow(cli).to receive(:read_gem_version_manifest_json).and_return(mocked_gem_version_manifest_json)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "does not print versions of tools with missing or errored tools" do
|
189
|
+
allow(cli).to receive(:read_gem_version_manifest_json).and_return("{}")
|
190
|
+
allow(cli).to receive(:read_version_manifest_json).and_return("{}")
|
191
|
+
run_cli(0)
|
192
|
+
expect(stdout).to eq(full_table_with_unknown_version_message)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "prints a table with the version of all the tools" do
|
196
|
+
run_cli(0)
|
197
|
+
expect(stdout).to eq(full_table_with_version_message)
|
198
|
+
end
|
155
199
|
end
|
156
200
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
201
|
+
context "#via_shell_out" do
|
202
|
+
let(:tools) do
|
203
|
+
{
|
204
|
+
"Chef Infra Client" => {
|
205
|
+
"command" => "chef-client",
|
206
|
+
"version_output" => "Chef Infra Client: 15.0.300",
|
207
|
+
"expected_version" => "15.0.300",
|
208
|
+
},
|
209
|
+
"Chef InSpec" => {
|
210
|
+
"command" => "inspec",
|
211
|
+
"version_output" => "4.6.2\n\nYour version of InSpec is out of date! The latest version is 4.6.4.",
|
212
|
+
"expected_version" => "4.6.2",
|
213
|
+
},
|
214
|
+
"Test Kitchen" => {
|
215
|
+
"command" => "kitchen",
|
216
|
+
"version_output" => "Test Kitchen version 2.2.5",
|
217
|
+
"expected_version" => "2.2.5",
|
218
|
+
},
|
219
|
+
"Cookstyle" => {
|
220
|
+
"command" => "cookstyle",
|
221
|
+
"version_output" => "Cookstyle 4.0.0\n * RuboCop 0.62.0",
|
222
|
+
"expected_version" => "4.0.0",
|
223
|
+
},
|
224
|
+
}
|
225
|
+
end
|
226
|
+
|
227
|
+
it "does not print versions of tools with missing or errored tools" do
|
228
|
+
full_version_message = version_message
|
229
|
+
tools.each do |name, details|
|
230
|
+
if name == "inspec"
|
231
|
+
expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(1, "#{details["version_output"]}", ""))
|
232
|
+
full_version_message += "#{name} version: ERROR\n"
|
233
|
+
else
|
234
|
+
expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(0, "#{details["version_output"]}", ""))
|
235
|
+
full_version_message += "#{name} version: #{details["expected_version"]}\n"
|
236
|
+
end
|
166
237
|
end
|
238
|
+
run_cli(0)
|
239
|
+
expect(stdout).to eq(full_version_message)
|
167
240
|
end
|
168
|
-
run_cli(0)
|
169
|
-
expect(stdout).to eq(full_version_message)
|
170
|
-
end
|
171
241
|
|
172
|
-
|
173
|
-
|
242
|
+
it "prints the version and versions of chef-cli tools" do
|
243
|
+
run_cli_and_validate_tool_versions
|
244
|
+
end
|
174
245
|
end
|
175
246
|
end
|
176
247
|
|
@@ -120,6 +120,17 @@ describe ChefCLI::Policyfile::GitLockFetcher do
|
|
120
120
|
expect(lock_data).to include(minimal_lockfile_modified)
|
121
121
|
end
|
122
122
|
|
123
|
+
# Shellout libraries on Windows expect cwd to be provided as a string, not Pathname object
|
124
|
+
it "provides the working directory as a string" do
|
125
|
+
expect(Mixlib::ShellOut).to receive(:new).with(/git clone/, {}).and_return(shellout)
|
126
|
+
expect(Mixlib::ShellOut).to receive(:new).with(/git show/, { cwd: /cache/ }).and_return(shellout)
|
127
|
+
allow(shellout).to receive(:error?).and_return(false)
|
128
|
+
allow(shellout).to receive(:stdout).and_return(minimal_lockfile_json)
|
129
|
+
allow(Dir).to receive(:chdir).and_return(0)
|
130
|
+
|
131
|
+
expect(lock_data).to include(minimal_lockfile_modified)
|
132
|
+
end
|
133
|
+
|
123
134
|
context "when using a relative path for the policyfile" do
|
124
135
|
let(:source_options_rel) do
|
125
136
|
source_options.collect { |k, v| [k.to_s, v] }.to_h.merge({ "rel" => rel })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.13
|
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-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-cli
|