Skip to content

Commit 52d51c3

Browse files
Merge pull request #8932 from joshcooper/pup-11604-add-unmet-deps-to-json
(PUP-11604) List unmet deps in --render-as json
2 parents 8324247 + b86a612 commit 52d51c3

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

lib/puppet/face/module/list.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@
6060
when_invoked do |options|
6161
Puppet::ModuleTool.set_option_defaults(options)
6262
environment = options[:environment_instance]
63+
modules_by_path = environment.modules_by_path
6364

6465
{
6566
:environment => environment,
66-
:modules_by_path => environment.modules_by_path,
67+
:modules_by_path => modules_by_path,
68+
:unmet_dependencies => unmet_dependencies(environment),
6769
}
6870
end
6971

@@ -103,12 +105,13 @@
103105
end
104106
end
105107

106-
def warn_unmet_dependencies(environment)
108+
109+
def unmet_dependencies(environment)
107110
error_types = [:non_semantic_version, :version_mismatch, :missing]
108111

109-
@unmet_deps = {}
112+
unmet_deps = {}
110113
error_types.each do |type|
111-
@unmet_deps[type] = Hash.new do |hash, key|
114+
unmet_deps[type] = Hash.new do |hash, key|
112115
hash[key] = { :errors => [], :parent => nil }
113116
end
114117
end
@@ -130,16 +133,22 @@ def warn_unmet_dependencies(environment)
130133
parent_version = dep[:parent][:version]
131134

132135
msg = _("'%{parent_name}' (%{parent_version}) requires '%{dependency_name}' (%{dependency_version})") % { parent_name: parent_name, parent_version: parent_version, dependency_name: dep_name, dependency_version: version_constraint }
133-
@unmet_deps[type][dep[:name]][:errors] << msg
134-
@unmet_deps[type][dep[:name]][:parent] = {
136+
unmet_deps[type][dep[:name]][:errors] << msg
137+
unmet_deps[type][dep[:name]][:parent] = {
135138
:name => dep[:parent][:name],
136139
:version => parent_version
137140
}
138-
@unmet_deps[type][dep[:name]][:version] = installed_version
141+
unmet_deps[type][dep[:name]][:version] = installed_version
139142
end
140143
end
141144
end
142145
end
146+
unmet_deps
147+
end
148+
149+
150+
def warn_unmet_dependencies(environment)
151+
@unmet_deps = unmet_dependencies(environment)
143152

144153
# Display unmet dependencies by category.
145154
error_display_order = [:non_semantic_version, :version_mismatch, :missing]

spec/unit/face/module/list_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,30 @@ def console_output(options={})
227227
console_output(:tree => true)
228228
end
229229
end
230+
231+
describe "when rendering as json" do
232+
let(:face) { Puppet::Face[:module, :current] }
233+
let(:action) { face.get_action(:list) }
234+
235+
it "should warn about missing dependencies" do
236+
PuppetSpec::Modules.create('depender', @modpath1, :metadata => {
237+
:version => '1.0.0',
238+
:dependencies => [{
239+
"version_requirement" => ">= 0.0.5",
240+
"name" => "puppetlabs/dependable"
241+
}]
242+
})
243+
244+
result = face.list
245+
expect(result.dig(:unmet_dependencies, :missing)).to include(
246+
"puppetlabs/dependable" => {
247+
errors: ["'puppetlabs-depender' (v1.0.0) requires 'puppetlabs-dependable' (>= 0.0.5)"],
248+
parent: {
249+
name: "puppetlabs/depender", :version=>"v1.0.0"
250+
},
251+
version: nil
252+
}
253+
)
254+
end
255+
end
230256
end

0 commit comments

Comments
 (0)