Skip to content

Commit 21ddfb0

Browse files
committed
Deal with rspec-puppet's Puppet::Resource
When testing the relations in rspec-puppet, it turns out that there are other classes and they don't match which breaks tests.
1 parent b74f62c commit 21ddfb0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/puppet_x/certs/common.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ module Common
5151

5252
validate do |value|
5353
ca_resource = resource.catalog.resource(value.to_s)
54-
if ca_resource && ca_resource.class.to_s != 'Puppet::Type::Ca'
55-
raise ArgumentError, "Expected Ca resource, got #{ca_resource.class} #{ca_resource.inspect}"
54+
if ca_resource
55+
# rspec-puppet presents Puppet::Resource instances
56+
resource_type = ca_resource.is_a?(Puppet::Resource) ? ca_resource.resource_type.to_s : ca_resource.class.to_s
57+
if resource_type != 'Puppet::Type::Ca'
58+
raise ArgumentError, "Expected Ca resource, got #{ca_resource.class} #{ca_resource.inspect}"
59+
end
60+
else
61+
raise ArgumentError, "Ca #{value} not found in catalog"
5662
end
5763
end
5864
end
@@ -90,15 +96,13 @@ module Common
9096
param_resource = resource.catalog.resource(value.to_s)
9197

9298
if param_resource
93-
param_resource_type = if param_resource.is_a?(Puppet::Resource)
94-
param_resource.resource_type
95-
else
96-
param_resource.to_resource.resource_type
97-
end
98-
99-
unless ['Puppet::Type::Ca', 'Puppet::Type::Cert'].include?(param_resource_type.to_s)
100-
raise ArgumentError, "Expected Ca or Cert resource, got #{param_resource_type} #{param_resource.inspect}"
99+
# rspec-puppet presents Puppet::Resource instances
100+
resource_type = param_resource.is_a?(Puppet::Resource) ? param_resource.resource_type : param_resource.class
101+
unless ['Puppet::Type::Ca', 'Puppet::Type::Cert'].include?(resource_type.to_s)
102+
raise ArgumentError, "Expected Ca or Cert resource, got #{resource_type} #{param_resource.inspect}"
101103
end
104+
else
105+
raise ArgumentError, "Key_pair #{value} not found in catalog"
102106
end
103107
end
104108
end

0 commit comments

Comments
 (0)