Skip to content

Commit cb71fb2

Browse files
authored
Merge pull request #180 from github/kpaulisse-ruby-version-test-update
Update build matrix to reflect Puppet's supported ruby version
2 parents ec42303 + d44c889 commit cb71fb2

24 files changed

+100
-25
lines changed

.travis.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ script: "script/cibuild"
66

77
matrix:
88
include:
9+
# Puppet supports ruby 2.4 with Puppet >= 5.0 so this should be considered the "official" build
10+
- rvm: 2.4
11+
env: RUBOCOP_TEST="true" RSPEC_TEST="true" PUPPET_VERSIONS="5.4.0" ENFORCE_COVERAGE="true"
912
# Build with latest ruby
1013
- rvm: 2.5
11-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="3.8.7"
12-
- rvm: 2.5
13-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="4.10.8"
14-
- rvm: 2.5
15-
env: RUBOCOP_TEST="true" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="5.0.0"
16-
# Build with older ruby versions
17-
- rvm: 2.4
18-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
19-
- rvm: 2.3.2
20-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.8"
21-
- rvm: 2.2.3
22-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"
14+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.4.0"
15+
# Puppet supports ruby 2.0 and 2.1 with Puppet 4.x, but build with more recent versions too
16+
- rvm: 2.3
17+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.10"
18+
- rvm: 2.2
19+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.10"
20+
- rvm: 2.1
21+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.10"
22+
# For really old ruby versions only build 3.8.7
2323
- rvm: 2.1
2424
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
2525
- rvm: 2.0
2626
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
27-
- rvm: 2.0
28-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.2
1+
1.5.3

doc/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
</tr>
99
</thead><tbody>
1010

11+
<tr valign=top>
12+
<td>1.5.3</td>
13+
<td>2018-03-05</td>
14+
<td>
15+
<li><a href="https://github.com/github/octocatalog-diff/pull/176">#176</a>: (Enhancement) Normalize file resource titles in reference checks</li>
16+
</td>
17+
</tr>
18+
1119
<tr valign=top>
1220
<td>1.5.2</td>
1321
<td>2017-12-19</td>

doc/requirements.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
To run `octocatalog-diff` you will need these basics:
44

5-
- Ruby 2.0 through 2.4 (we test octocatalog-diff with Ruby 2.0, 2.1, 2.2, 2.3, and 2.4)
5+
- An appropriate Puppet version and [corresponding ruby version](https://puppet.com/docs/puppet/5.4/system_requirements.html)
6+
- Puppet 5.x officially supports Ruby 2.4
7+
- Puppet 4.x officially supports Ruby 2.1, but seems to work fine with later versions as well
8+
- Puppet 3.8.7 -- we attempt to maintain compatibility in `octocatalog-diff` to facilitate upgrades even though this version is no longer supported by Puppet
9+
- We don't officially support Puppet 3.8.6 or before
610
- Mac OS, Linux, or other Unix-line operating system (Windows is not supported)
711
- Ability to install gems, e.g. with [rbenv](https://github.com/rbenv/rbenv) or [rvm](https://rvm.io/), or root privileges to install into the system Ruby
8-
- Puppet agent for [Linux](https://docs.puppet.com/puppet/latest/reference/install_linux.html) or [Mac OS X](https://docs.puppet.com/puppet/latest/reference/install_osx.html), or installed as a gem (we support Puppet 3.8.7 and all versions of Puppet 4.x)
12+
- Puppet agent for [Linux](https://docs.puppet.com/puppet/latest/reference/install_linux.html) or [Mac OS X](https://docs.puppet.com/puppet/latest/reference/install_osx.html), or installed as a gem
913

1014
We recommend that you also have the following to get the most out of `octocatalog-diff`, but these are not absolute requirements:
1115

lib/octocatalog-diff/catalog.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,32 @@ def resources_missing_from_catalog(resources_to_check)
304304
unless res =~ /\A([\w:]+)\[(.+)\]\z/
305305
raise ArgumentError, "Resource #{res} is not in the expected format"
306306
end
307-
resource(type: Regexp.last_match(1), title: Regexp.last_match(2)).nil?
307+
308+
type = Regexp.last_match(1)
309+
title = normalized_title(Regexp.last_match(2), type)
310+
resource(type: type, title: title).nil?
308311
end
309312
end
310313

314+
# Private method: Given a title string, normalize it according to the rules
315+
# used by puppet 4.10.x for file resource title normalization:
316+
# https://github.com/puppetlabs/puppet/blob/4.10.x/lib/puppet/type/file.rb#L42
317+
def normalized_title(title_string, type)
318+
return title_string if type != 'File'
319+
320+
matches = title_string.match(%r{^(?<normalized_path>/|.+:/|.*[^/])/*\Z}m)
321+
matches[:normalized_path] || title_string
322+
end
323+
311324
# Private method: Build the resource hash to be used used for O(1) lookups by type and title.
312325
# This method is called the first time the resource hash is accessed.
313326
def build_resource_hash
314327
@resource_hash = {}
315328
resources.each do |resource|
316329
@resource_hash[resource['type']] ||= {}
317-
@resource_hash[resource['type']][resource['title']] = resource
330+
331+
title = normalized_title(resource['title'], resource['type'])
332+
@resource_hash[resource['type']][title] = resource
318333

319334
if resource.key?('parameters') && resource['parameters'].key?('alias')
320335
@resource_hash[resource['type']][resource['parameters']['alias']] = resource

octocatalog-diff.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'json'
22

3-
DEFAULT_PUPPET_VERSION = '4.10.8'.freeze
3+
DEFAULT_PUPPET_VERSION = '5.4.0'.freeze
44

55
Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 2.0.0'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
classes:
3+
- test::file_tests
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class test::file_tests {
2+
file { '/foo':
3+
ensure => directory,
4+
}
5+
6+
file { '/bar':
7+
ensure => directory,
8+
require => File['/foo/'],
9+
}
10+
}

spec/octocatalog-diff/integration/reference_validation_spec.rb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ def self.catalog_contains_resource(result, type, title)
9393
end
9494
end
9595

96+
context 'with valid files that have trailing slashes' do
97+
before(:all) do
98+
@result = OctocatalogDiff::Spec.reference_validation_catalog('working-file', %w(require))
99+
end
100+
101+
it 'should succeed' do
102+
expect(@result.exitcode).to eq(0)
103+
end
104+
105+
it 'should not raise any exceptions' do
106+
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
107+
end
108+
109+
it 'should contain representative resources' do
110+
pending 'Catalog failed' unless @result.exitcode.zero?
111+
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'File', '/foo')).to eq(true)
112+
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'File', '/bar')).to eq(true)
113+
end
114+
end
115+
96116
context 'with broken subscribe' do
97117
before(:all) do
98118
@result = OctocatalogDiff::Spec.reference_validation_catalog('broken-subscribe', %w(subscribe))
@@ -109,7 +129,7 @@ def self.catalog_contains_resource(result, type, title)
109129
if OctocatalogDiff::Spec.is_puppet5?
110130
it 'should pass through the error messages from Puppet' do
111131
msg = @result.exception.message
112-
expect(msg).to match(/Error: Could not find resource 'Exec\[subscribe target\]' in parameter 'subscribe' at/)
132+
expect(msg).to match(/Error: Could not find resource 'Exec\[subscribe target\]' in parameter 'subscribe'/)
113133
end
114134
else
115135
# Multiple line numbers given because Puppet 4.x and 3.8 correspond to first and last line of resource, respectively.
@@ -142,7 +162,7 @@ def self.catalog_contains_resource(result, type, title)
142162
if OctocatalogDiff::Spec.is_puppet5?
143163
it 'should pass through the error messages from Puppet' do
144164
msg = @result.exception.message
145-
expect(msg).to match(/Error: Could not find resource 'Exec\[before target\]' in parameter 'before' at/)
165+
expect(msg).to match(/Error: Could not find resource 'Exec\[before target\]' in parameter 'before'/)
146166
end
147167
else
148168
# rubocop:disable Metrics/LineLength
@@ -170,7 +190,7 @@ def self.catalog_contains_resource(result, type, title)
170190
if OctocatalogDiff::Spec.is_puppet5?
171191
it 'should pass through the error messages from Puppet' do
172192
msg = @result.exception.message
173-
expect(msg).to match(/Error: Could not find resource 'Test::Foo::Bar\[notify target\]' in parameter 'notify' at/)
193+
expect(msg).to match(/Error: Could not find resource 'Test::Foo::Bar\[notify target\]' in parameter 'notify'/)
174194
end
175195
else
176196
# rubocop:disable Metrics/LineLength
@@ -198,7 +218,7 @@ def self.catalog_contains_resource(result, type, title)
198218
if OctocatalogDiff::Spec.is_puppet5?
199219
it 'should pass through the error messages from Puppet' do
200220
msg = @result.exception.message
201-
expect(msg).to match(/Error: Could not find resource 'Exec\[require target\]' in parameter 'require' at/)
221+
expect(msg).to match(/Error: Could not find resource 'Exec\[require target\]' in parameter 'require'/)
202222
end
203223
else
204224
# rubocop:disable Metrics/LineLength
@@ -226,7 +246,7 @@ def self.catalog_contains_resource(result, type, title)
226246

227247
it 'should pass through the error messages from Puppet' do
228248
msg = @result.exception.message
229-
expect(msg).to match(/Error: Could not find resource 'Exec\[subscribe target\]' in parameter 'subscribe' at/)
249+
expect(msg).to match(/Error: Could not find resource 'Exec\[subscribe target\]' in parameter 'subscribe'/)
230250
end
231251
else
232252
it 'should succeed' do

spec/octocatalog-diff/tests/catalog_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,14 @@
621621
'alias' => 'the exec',
622622
'command' => '/bin/true'
623623
}
624+
},
625+
{
626+
'type' => 'File',
627+
'title' => '/foo/'
628+
},
629+
{
630+
'type' => 'File',
631+
'title' => '/bar'
624632
}
625633
]
626634
described_object = described_class.allocate
@@ -636,5 +644,14 @@
636644
it 'should contain the entry for the aliased resource' do
637645
expect(@resource_hash['Exec']['the exec']).to be_a_kind_of(Hash)
638646
end
647+
648+
it 'should normalize trailing slashes on file resources' do
649+
expect(@resource_hash['File']['/foo']).to be_a_kind_of(Hash)
650+
expect(@resource_hash['File']['/foo/']).to eq(nil)
651+
end
652+
653+
it 'should not otherwise touch file resources that do not need to be normalized' do
654+
expect(@resource_hash['File']['/bar']).to be_a_kind_of(Hash)
655+
end
639656
end
640657
end

0 commit comments

Comments
 (0)