Skip to content

Commit

Permalink
(maint) Add a better example and tests
Browse files Browse the repository at this point in the history
The example in the docs for extra_config_section of an array of hashes
is quite confusing, as it leads the reader to believe that the best way
of implementing refresh_patterns is via extra_config_section.

Here, I replace this with a more realistic example using always_direct.

Further, I add a passing unit test case for the array of hashes case.
  • Loading branch information
alex-harvey-z3q committed Oct 5, 2017
1 parent 74f80a2 commit a88a727
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,23 @@ mail_program mail
And using an array:

```puppet
squid::extra_config_section { 'refresh patterns':
squid::extra_config_section { 'always_directs':
order => '60',
config_entries => [{
'refresh_pattern' => ['^ftp: 1440 20% 10080',
'^gopher: 1440 0% 1440',
'-i (/cgi-bin/|\?) 0 0% 0',
'. 0 20% 4320'],
'always_direct' => ['deny www.reallyreallybadplace.com',
'allow my-good-dst',
'allow my-other-good-dst'],
}],
}
```

Results in a squid configuration of

```
# refresh_patterns
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
# always_directs
always_direct deny www.reallyreallybadplace.com
always_direct allow my-good-dst
always_direct allow my-other-good-dst
```

#### Parameters for Type squid::extra\_config\_section
Expand Down
42 changes: 35 additions & 7 deletions spec/defines/extra_config_section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
let(:facts) do
facts
end
let :pre_condition do
let(:pre_condition) do
' class{"::squid":
config => "/tmp/squid.conf"
}
'
end
let(:title) { 'my config section' }

expected_config_section = %(# my config section\n)
expected_config_section += %(ssl_bump server-first all\n)
expected_config_section += %(sslcrtd_program /usr/lib64/squid/ssl_crtd -s /var/lib/ssl_db -M 4MB\n)
expected_config_section += %(sslcrtd_children 8 startup=1 idle=1\n)
expected_config_section += %(\n)

context 'when config entry parameters are strings' do
let(:params) do
{
Expand All @@ -31,6 +25,12 @@
}
end

expected_config_section = %(# my config section\n)
expected_config_section += %(ssl_bump server-first all\n)
expected_config_section += %(sslcrtd_program /usr/lib64/squid/ssl_crtd -s /var/lib/ssl_db -M 4MB\n)
expected_config_section += %(sslcrtd_children 8 startup=1 idle=1\n)
expected_config_section += %(\n)

it { is_expected.to contain_concat_fragment('squid_extra_config_section_my config section').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_extra_config_section_my config section').with_order('60-my config section') }
it 'config section' do
Expand All @@ -49,6 +49,34 @@
}
end

expected_config_section = %(# my config section\n)
expected_config_section += %(ssl_bump server-first all\n)
expected_config_section += %(sslcrtd_program /usr/lib64/squid/ssl_crtd -s /var/lib/ssl_db -M 4MB\n)
expected_config_section += %(sslcrtd_children 8 startup=1 idle=1\n)
expected_config_section += %(\n)

it 'config section' do
content = catalogue.resource('concat_fragment', 'squid_extra_config_section_my config section').send(:parameters)[:content]
expect(content).to match(expected_config_section)
end
end
context 'when config entry parameters are arrays of hashes' do
let(:params) do
{
config_entries: [{
'always_direct' => ['deny www.reallyreallybadplace.com',
'allow my-good-dst',
'allow my-other-good-dst'],
}],
}
end

expected_config_section = %(# my config section\n)
expected_config_section += %(always_direct deny www.reallyreallybadplace.com\n)
expected_config_section += %(always_direct allow my-good-dst\n)
expected_config_section += %(always_direct allow my-other-good-dst\n)
expected_config_section += %(\n)

it 'config section' do
content = catalogue.resource('concat_fragment', 'squid_extra_config_section_my config section').send(:parameters)[:content]
expect(content).to match(expected_config_section)
Expand Down

0 comments on commit a88a727

Please sign in to comment.