Skip to content

Commit f3bec4c

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 03b79ae commit f3bec4c

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
@@ -59,8 +59,14 @@ module Common
5959

6060
validate do |value|
6161
ca_resource = resource.catalog.resource(value.to_s)
62-
if ca_resource && ca_resource.class.to_s != 'Puppet::Type::Ca'
63-
raise ArgumentError, "Expected Ca resource, got #{ca_resource.class} #{ca_resource.inspect}"
62+
if ca_resource
63+
# rspec-puppet presents Puppet::Resource instances
64+
resource_type = ca_resource.is_a?(Puppet::Resource) ? ca_resource.resource_type.to_s : ca_resource.class.to_s
65+
if resource_type != 'Puppet::Type::Ca'
66+
raise ArgumentError, "Expected Ca resource, got #{ca_resource.class} #{ca_resource.inspect}"
67+
end
68+
else
69+
raise ArgumentError, "Ca #{value} not found in catalog"
6470
end
6571
end
6672
end
@@ -98,15 +104,13 @@ module Common
98104
param_resource = resource.catalog.resource(value.to_s)
99105

100106
if param_resource
101-
param_resource_type = if param_resource.is_a?(Puppet::Resource)
102-
param_resource.resource_type
103-
else
104-
param_resource.to_resource.resource_type
105-
end
106-
107-
unless ['Puppet::Type::Ca', 'Puppet::Type::Cert'].include?(param_resource_type.to_s)
108-
raise ArgumentError, "Expected Ca or Cert resource, got #{param_resource_type} #{param_resource.inspect}"
107+
# rspec-puppet presents Puppet::Resource instances
108+
resource_type = param_resource.is_a?(Puppet::Resource) ? param_resource.resource_type : param_resource.class
109+
unless ['Puppet::Type::Ca', 'Puppet::Type::Cert'].include?(resource_type.to_s)
110+
raise ArgumentError, "Expected Ca or Cert resource, got #{resource_type} #{param_resource.inspect}"
109111
end
112+
else
113+
raise ArgumentError, "Key_pair #{value} not found in catalog"
110114
end
111115
end
112116
end

0 commit comments

Comments
 (0)