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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc470c0fa3a1a6580b9272b8f37fd8f09d3e64942b0d11d77de031f09a47db0e
4
- data.tar.gz: d7904dd289a5bac13b41199a2a2d446cd0b20d943887b8c0f013aa32ca9d429a
3
+ metadata.gz: 7b5f6126a4c90780ea0e12bfb21478a40bce4d2432735b5ce2e36c6114414d06
4
+ data.tar.gz: beed8e750ba8df274e82be2aa11238a07d55968d1686b7c1f0393c303639dc5f
5
5
  SHA512:
6
- metadata.gz: 865e84c90ffabeb94b902be984d890d841e040ed95d245f24bcce166d0b94e422faaec5001d92dcfef28f2fea70247f464f0daff869010db5eab9211be317b90
7
- data.tar.gz: 11511a9d36c5ff9c0fc1cdd969562c1550846707b0da2fe368289b93ef9e12d1cd31585ac4b8d7991ed7615b5a74cf265f0dd877a4babbd21db8651c01a70b69
6
+ metadata.gz: 82d425973ce0b4e17c55a2f536773a5c9ad40ba50bdcd2b537b64d04462d4b9d970d27d642574f86529839549235007778b8c77608dfb19352b1fdef79c11e0d
7
+ data.tar.gz: 041f50bcdc2cbaab8efdc1f51b53d279d6cf1b11a72deac5124885ad1e8acf52fb4ab052ff9dade90b60d2dcae7e88f7371bec74184504ff23655028bc0da13c
@@ -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
@@ -51,9 +51,9 @@ module ChefCLI
51
51
  # Locates the omnibus directories
52
52
  #
53
53
  def omnibus_install?
54
- # We also checck 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 or
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
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "1.0.11".freeze
19
+ VERSION = "1.0.13".freeze
20
20
  end
@@ -124,53 +124,124 @@ describe ChefCLI::CLI do
124
124
  context "given -v" do
125
125
  let(:argv) { %w{-v} }
126
126
 
127
- let(:tools) do
128
- {
129
- "Chef Infra Client" => {
130
- "command" => "chef-client",
131
- "version_output" => "Chef Infra Client: 15.0.300",
132
- "expected_version" => "15.0.300",
133
- },
134
- "Chef InSpec" => {
135
- "command" => "inspec",
136
- "version_output" => "4.6.2\n\nYour version of InSpec is out of date! The latest version is 4.6.4.",
137
- "expected_version" => "4.6.2",
138
- },
139
- "Test Kitchen" => {
140
- "command" => "kitchen",
141
- "version_output" => "Test Kitchen version 2.2.5",
142
- "expected_version" => "2.2.5",
143
- },
144
- "Foodcritic" => {
145
- "command" => "foodcritic",
146
- "version_output" => "foodcritic 16.0.0",
147
- "expected_version" => "16.0.0",
148
- },
149
- "Cookstyle" => {
150
- "command" => "cookstyle",
151
- "version_output" => "Cookstyle 4.0.0\n * RuboCop 0.62.0",
152
- "expected_version" => "4.0.0",
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
- it "does not print versions of tools with missing or errored tools" do
158
- full_version_message = version_message
159
- tools.each do |name, details|
160
- if name == "inspec"
161
- expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(1, "#{details["version_output"]}", ""))
162
- full_version_message += "#{name} version: ERROR\n"
163
- else
164
- expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(0, "#{details["version_output"]}", ""))
165
- full_version_message += "#{name} version: #{details["expected_version"]}\n"
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
- it "prints the version and versions of chef-cli tools" do
173
- run_cli_and_validate_tool_versions
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.11
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-07-25 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli