Skip to content

Commit

Permalink
(PUP-5088) Ensure only => can be used in capability mappings
Browse files Browse the repository at this point in the history
This commit relaxes that constraint that a CapabilityMapping
only can contain an AttributeOperation so that it instead can
contain an AbstractAttributeOperation. This was done to prevent
a cryptic error message when an AttributesOperation (note the
plural) was assigned due to use of *=> operator. The relaxed
constraint lets this pass so that it instead can be trapped
in the validator where a correct check was already in place.
  • Loading branch information
thallgren committed Aug 26, 2015
1 parent 6283740 commit b80832a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/pops/model/model_meta.rb
Expand Up @@ -542,7 +542,7 @@ class CapabilityMapping < Definition
has_attr 'kind', String, :lowerBound => 1
has_attr 'resource', String, :lowerBound => 1
has_attr 'capability', String, :lowerBound => 1
contains_many_uni 'mappings', AttributeOperation
contains_many_uni 'mappings', AbstractAttributeOperation
end

# A resource defaults sets defaults for a resource type. This class inherits from AbstractResource
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/capability_spec.rb
Expand Up @@ -63,6 +63,34 @@
expect(cns[:mappings]["host"]).to be_instance_of(Puppet::Parser::AST::PopsBridge::Expression)
end

it "does not allow operator '+>' in a mapping" do
expect do
compile_to_catalog(<<-MANIFEST)
define test($hostname) {
notify { "hostname ${hostname}":}
}
Test consumes Cap {
host +> $hostname
}
MANIFEST
end.to raise_error(Puppet::ParseErrorWithIssue, /Illegal \+> operation on attribute/)
end

it "does not allow operator '*=>' in a mapping" do
expect do
compile_to_catalog(<<-MANIFEST)
define test($hostname) {
notify { "hostname ${hostname}":}
}
Test consumes Cap {
*=> $hostname
}
MANIFEST
end.to raise_error(Puppet::ParseError, /The operator '\* =>' in a Block Expression is not supported/)
end


["produces", "consumes"].each do |kw|
it "creates an error when #{kw} references nonexistent type" do
Expand Down

0 comments on commit b80832a

Please sign in to comment.