Skip to content

Commit

Permalink
Add a Squid::Size type
Browse files Browse the repository at this point in the history
This type correctly checks the type for sizes. It now allows specifying
the maximum_object_size_in_memory in MBs rather than KBs. For
correctness we now also check for the full string which means we no
longer allow -1 KB or 1 KBB.
  • Loading branch information
ekohl committed Dec 2, 2018
1 parent 4839f3e commit 19a5fb9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class squid (
String $access_log = $squid::params::access_log,
Pattern[/\d+ MB/] $cache_mem = $squid::params::cache_mem,
Squid::Size $cache_mem = $squid::params::cache_mem,
String $config = $squid::params::config,
String $config_group = $squid::params::config_group,
String $config_user = $squid::params::config_user,
String $daemon_group = $squid::params::daemon_group,
String $daemon_user = $squid::params::daemon_user,
Boolean $enable_service = $squid::params::enable_service,
String $ensure_service = $squid::params::ensure_service,
Pattern[/\d+ KB/] $maximum_object_size_in_memory = $squid::params::maximum_object_size_in_memory,
Squid::Size $maximum_object_size_in_memory = $squid::params::maximum_object_size_in_memory,
String $package_name = $squid::params::package_name,
String $service_name = $squid::params::service_name,
Optional[Stdlib::Absolutepath] $error_directory = $squid::params::error_directory,
Expand Down
15 changes: 15 additions & 0 deletions spec/type_aliases/squid_size_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe 'Squid::Size' do
it { is_expected.to allow_value('1 KB') }
it { is_expected.to allow_value('1 MB') }
it { is_expected.to allow_value('10 KB') }
it { is_expected.to allow_value('9876543210 KB') }
it { is_expected.not_to allow_value('-1 KB') }
it { is_expected.not_to allow_value('1 kB') }
it { is_expected.not_to allow_value('1 Kb') }
it { is_expected.not_to allow_value('1 Mb') }
it { is_expected.not_to allow_value('1 KBB') }
it { is_expected.not_to allow_value('a KBB') }
it { is_expected.not_to allow_value('1KB') }
end
1 change: 1 addition & 0 deletions types/size.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Squid::Size = Pattern[/^\d+ [KM]B$/]

0 comments on commit 19a5fb9

Please sign in to comment.