Skip to content

Commit a8e377d

Browse files
authored
Merge pull request #202 from bwitt/add-os-filter-fix
Fix `add_supported_os` with os filter
2 parents 5eb9954 + 3d95e45 commit a8e377d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/puppet_metadata/command/add_supported_os.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.parser(options)
88
opts.on('--at DATE', Date, 'The date to use') do |value|
99
options[:at] = value
1010
end
11-
opts.on('--os operatingsystem', nil, 'Only honour the specific operating system') do |value|
11+
opts.on('--os OPERATINGSYSTEM', 'Only honour the specific operating system') do |value|
1212
options[:os] = value
1313
end
1414
end

lib/puppet_metadata/metadata.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ def add_supported_operatingsystems(at = nil, desired_os = nil)
123123

124124
# desired_os is a filter
125125
# if set, we only care about this OS, otherwise we want all OSes from metadata.json
126-
next if desired_os && desired_os != os
126+
if desired_os && desired_os != os
127+
# Preserve the original entry unchanged
128+
result['operatingsystemrelease'] = releases unless releases.nil?
129+
next result
130+
end
127131

128132
unless releases.nil?
129133
supported = OperatingSystem.supported_releases(os, at)
@@ -134,6 +138,9 @@ def add_supported_operatingsystems(at = nil, desired_os = nil)
134138
result
135139
end
136140

141+
# Clear the memoized operatingsystems so it gets recalculated
142+
@operatingsystems = nil
143+
137144
added
138145
end
139146

spec/metadata_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,19 @@
229229
end
230230

231231
it 'with OS' do
232+
# Only Debian should be in the added hash
232233
expect(subject.add_supported_operatingsystems(nil, desired_os)).to eq({ 'Debian' => ['11', '12', '13'] })
234+
# Other OSes should remain unchanged
235+
expect(subject.operatingsystems['CentOS']).to eq(['7', '8', '9'])
236+
expect(subject.operatingsystems['RedHat']).to eq(['7', '8', '9'])
233237
end
234238

235239
it 'with date & OS' do
240+
# Only Debian should be in the added hash
236241
expect(subject.add_supported_operatingsystems(date, desired_os)).to eq({ 'Debian' => ['12', '13'] })
242+
# Other OSes should remain unchanged
243+
expect(subject.operatingsystems['CentOS']).to eq(['7', '8', '9'])
244+
expect(subject.operatingsystems['RedHat']).to eq(['7', '8', '9'])
237245
end
238246
end
239247
end

0 commit comments

Comments
 (0)