Skip to content

Commit

Permalink
Mark context and target as namevars (GH #3)
Browse files Browse the repository at this point in the history
Add title_patterns
  • Loading branch information
raphink committed Feb 15, 2016
1 parent df7fe27 commit 183289f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/puppet/type/apache_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def insync?(is)

newparam(:context) do
desc 'The path where the directive is located. Expressed as an Augeas path expression.'
isnamevar
defaultto ''
end

Expand All @@ -51,5 +52,40 @@ def insync?(is)

newparam(:target) do
desc 'The config file to use'
isnamevar
end

def self.title_patterns
identity = lambda { |x| x }
[
[
/^(\S+)\s+from\s+(\S+)\s+in\s+(.*)$/,
[
[ :name, identity ],
[ :context, identity ],
[ :target, identity ],
]
],
[
/^(\S+)\s+from\s+(\S+)$/,
[
[ :name, identity ],
[ :context, identity ],
]
],
[
/^(\S+)\s+in\s+(.*)$/,
[
[ :name, identity ],
[ :target, identity ],
]
],
[
/(.*)/,
[
[ :name, identity ],
]
]
]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ KeepAliveTimeout 5
MaxRequestsPerChild 0
</IfModule>

<IfModule ssl_module>
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
Expand Down
41 changes: 41 additions & 0 deletions spec/unit/puppet/provider/apache_directive/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@
{ "directive" = "Example" }
')
end

it "should fail with same name" do
expect do
apply!(
Puppet::Type.type(:apache_directive).new(
:name => "Listen",
:args => "80",
:target => target,
:provider => "augeas"
),
Puppet::Type.type(:apache_directive).new(
:name => "Listen",
:args => "443",
:target => target,
:provider => "augeas"
)
)
end.to raise_error(Puppet::Resource::Catalog::DuplicateResourceError)
end
end

context "when creating with context" do
Expand Down Expand Up @@ -167,6 +186,28 @@
aug.get("IfModule[arg='mpm_worker_module']/directive[.='StartServers']/arg").should == '2'
end
end

it "should not fail with different names and different context" do
expect do
apply!(
Puppet::Type.type(:apache_directive).new(
:title => "Listen80",
:name => "Listen",
:args => "80",
:target => target,
:provider => "augeas"
),
Puppet::Type.type(:apache_directive).new(
:title => "Listen443",
:name => "Listen",
:args => "443",
:context => 'IfModule[arg="ssl_module"]',
:target => target,
:provider => "augeas"
)
)
end.not_to raise_error
end
end
end

Expand Down

0 comments on commit 183289f

Please sign in to comment.