From 4aa519e998f2f4ce567bcaae5880800884a44bf6 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Thu, 6 Oct 2016 14:19:14 +0100 Subject: Corrects Puppet version for compat types tests --- spec/aliases/absolute_path_spec.rb | 2 +- spec/aliases/array_spec.rb | 2 +- spec/aliases/bool_spec.rb | 2 +- spec/aliases/float_spec.rb | 2 +- spec/aliases/integer_spec.rb | 2 +- spec/aliases/ip_address.rb | 2 +- spec/aliases/ipv4_spec.rb | 2 +- spec/aliases/ipv6_spec.rb | 2 +- spec/aliases/numeric_spec.rb | 2 +- spec/aliases/string_spec.rb | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb index 0bcdf85..3fb9d12 100644 --- a/spec/aliases/absolute_path_spec.rb +++ b/spec/aliases/absolute_path_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::absolute_path', type: :class do describe 'valid paths handling' do %w{ diff --git a/spec/aliases/array_spec.rb b/spec/aliases/array_spec.rb index 8bbb8b3..d0f9877 100644 --- a/spec/aliases/array_spec.rb +++ b/spec/aliases/array_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::array', type: :class do describe 'accepts arrays' do [ diff --git a/spec/aliases/bool_spec.rb b/spec/aliases/bool_spec.rb index f664457..78c57fc 100644 --- a/spec/aliases/bool_spec.rb +++ b/spec/aliases/bool_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::bool', type: :class do describe 'accepts booleans' do [ diff --git a/spec/aliases/float_spec.rb b/spec/aliases/float_spec.rb index be31e43..cc20758 100644 --- a/spec/aliases/float_spec.rb +++ b/spec/aliases/float_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::float', type: :class do describe 'accepts floats' do [ diff --git a/spec/aliases/integer_spec.rb b/spec/aliases/integer_spec.rb index fbc8c19..260090a 100644 --- a/spec/aliases/integer_spec.rb +++ b/spec/aliases/integer_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::integer', type: :class do describe 'accepts integers' do [ diff --git a/spec/aliases/ip_address.rb b/spec/aliases/ip_address.rb index 036bfe5..664bf24 100644 --- a/spec/aliases/ip_address.rb +++ b/spec/aliases/ip_address.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::ip_address', type: :class do describe 'accepts ipv4 and ipv6 addresses' do [ diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb index 640618c..e767b45 100644 --- a/spec/aliases/ipv4_spec.rb +++ b/spec/aliases/ipv4_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::ipv4', type: :class do describe 'accepts ipv4 addresses' do [ diff --git a/spec/aliases/ipv6_spec.rb b/spec/aliases/ipv6_spec.rb index 688eb16..13d7c3e 100644 --- a/spec/aliases/ipv6_spec.rb +++ b/spec/aliases/ipv6_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::ipv6', type: :class do describe 'accepts ipv6 addresses' do [ diff --git a/spec/aliases/numeric_spec.rb b/spec/aliases/numeric_spec.rb index 9afe4ed..0e98bee 100644 --- a/spec/aliases/numeric_spec.rb +++ b/spec/aliases/numeric_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::numeric', type: :class do describe 'accepts numerics' do [ diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb index 853b5af..8a93585 100644 --- a/spec/aliases/string_spec.rb +++ b/spec/aliases/string_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::string', type: :class do describe 'accepts strings' do [ -- cgit v1.2.3 From 83539371e5b1e6ff412eda48c3a725653c506ece Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Thu, 6 Oct 2016 14:22:13 +0100 Subject: Addition of several new types --- README.markdown | 48 ++++++++++++++++++++++++--- spec/aliases/absolutepath_spec.rb | 49 ++++++++++++++++++++++++++++ spec/aliases/httpsurl_spec.rb | 40 +++++++++++++++++++++++ spec/aliases/httpurl_spec.rb | 43 ++++++++++++++++++++++++ spec/aliases/unixpath_spec.rb | 41 +++++++++++++++++++++++ spec/aliases/windowspath_spec.rb | 44 +++++++++++++++++++++++++ spec/fixtures/test/manifests/absolutepath.pp | 6 ++++ spec/fixtures/test/manifests/httpsurl.pp | 6 ++++ spec/fixtures/test/manifests/httpurl.pp | 6 ++++ spec/fixtures/test/manifests/unixpath.pp | 6 ++++ spec/fixtures/test/manifests/windowspath.pp | 6 ++++ types/absolutepath.pp | 2 ++ types/httpsurl.pp | 1 + types/httpurl.pp | 1 + types/unixpath.pp | 2 ++ types/windowspath.pp | 1 + 16 files changed, 298 insertions(+), 4 deletions(-) create mode 100644 spec/aliases/absolutepath_spec.rb create mode 100644 spec/aliases/httpsurl_spec.rb create mode 100644 spec/aliases/httpurl_spec.rb create mode 100644 spec/aliases/unixpath_spec.rb create mode 100644 spec/aliases/windowspath_spec.rb create mode 100644 spec/fixtures/test/manifests/absolutepath.pp create mode 100644 spec/fixtures/test/manifests/httpsurl.pp create mode 100644 spec/fixtures/test/manifests/httpurl.pp create mode 100644 spec/fixtures/test/manifests/unixpath.pp create mode 100644 spec/fixtures/test/manifests/windowspath.pp create mode 100644 types/absolutepath.pp create mode 100644 types/httpsurl.pp create mode 100644 types/httpurl.pp create mode 100644 types/unixpath.pp create mode 100644 types/windowspath.pp diff --git a/README.markdown b/README.markdown index d27668b..210e9f3 100644 --- a/README.markdown +++ b/README.markdown @@ -22,7 +22,7 @@ This module provides a standard library of resources for the development of Pupp * Facts * Functions * Defined resource types - * Types + * Data Types * Providers > *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules. @@ -73,7 +73,7 @@ The `stdlib::stages` class declares various run stages for deploying infrastruct * `stdlib::stages`: Manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently. -### Types +### Resource Types #### `file_line` @@ -134,6 +134,46 @@ All parameters are optional, unless otherwise noted. * `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file. * `replace`: Defines whether the resource will overwrite an existing line that matches the `match` parameter. If set to false and a line is found matching the `match` param, the line will not be placed in the file. Valid options: true, false, yes, no. Default: true +### Data Types + +#### `absolutepath` + +A strict absolute path type. Uses a Variant of Unixpath and Windowspath types. + +Acceptable input examples: /usr2/username/bin:/usr/local/bin:/usr/bin:. + C:\\WINDOWS\\System32 + +#### `httpsurl` + +Matches https URLs. +Acceptable input example: https://hello.com +Unacceptable input example: httds://notquiteright.org + +#### `httpurl` + +Matches both https and http URLs. + +Acceptable input example: https://hello.com + http://hello.com +Unacceptable input example: httds://notquiteright.org + +#### `unixpath` + +Matches paths on Unix type Operating Systems. + +Acceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:. + /var/tmp +Unacceptable input example: C:/whatever + +#### `windowspath` + +Matches paths on Windows Operating systems. + +Acceptable input example: C:\\WINDOWS\\System32 + C:\\ + \\\\host\\windows +Unacceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:. + ### Functions #### `abs` @@ -1372,7 +1412,7 @@ The following values will fail, causing compilation to abort: Validates a value against both a specified type and a deprecated validation function. Silently passes if both pass, errors if only one validation passes, and fails if both validations return false. -Accepts arguments for: +Accepts arguments for: * the type to check the value against, * the full name of the previous validation function, * the value to be checked, @@ -1430,7 +1470,7 @@ class example( validate_legacy(Numeric, 'validate_numeric', $value) ~~~ -Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`). +Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`). The call to `validate_legacy` takes care of triggering the correct log or fail message for you. It requires the new type, the previous validation function name, and all arguments to that function. diff --git a/spec/aliases/absolutepath_spec.rb b/spec/aliases/absolutepath_spec.rb new file mode 100644 index 0000000..aa435d7 --- /dev/null +++ b/spec/aliases/absolutepath_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.5 + describe 'test::absolutepath', type: :class do + describe 'valid handling' do + %w{ + /usr2/username/bin:/usr/local/bin:/usr/bin:. + C:/ + C:\\ + C:\\WINDOWS\\System32 + C:/windows/system32 + X:/foo/bar + X:\\foo\\bar + \\\\host\\windows + //host/windows + /var/tmp + /var/opt/../lib/puppet + }.each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [ nil ], + [ nil, nil ], + { 'foo' => 'bar' }, + { }, + '', + "*/Users//nope", + "\\Users/hc/wksp/stdlib", + "C:noslashes", + "\\var\\tmp" + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Variant/) } + end + end + end + + end + end +end diff --git a/spec/aliases/httpsurl_spec.rb b/spec/aliases/httpsurl_spec.rb new file mode 100644 index 0000000..97ae006 --- /dev/null +++ b/spec/aliases/httpsurl_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.5 + describe 'test::httpsurl', type: :class do + describe 'valid handling' do + %w{ + https://hello.com + https://notcreative.org + https://notexciting.co.uk + }.each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [ nil ], + [ nil, nil ], + { 'foo' => 'bar' }, + { }, + '', + "httds://notquiteright.org", + "hptts:/nah", + "https;//notrightbutclose.org" + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::HTTPSUrl/) } + end + end + end + + end + end +end diff --git a/spec/aliases/httpurl_spec.rb b/spec/aliases/httpurl_spec.rb new file mode 100644 index 0000000..8bd57ca --- /dev/null +++ b/spec/aliases/httpurl_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.5 + describe 'test::httpurl', type: :class do + describe 'valid handling' do + %w{ + https://hello.com + https://notcreative.org + https://canstillaccepthttps.co.uk + http://anhttp.com + http://runningoutofideas.gov + http:// + }.each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [ nil ], + [ nil, nil ], + { 'foo' => 'bar' }, + { }, + '', + "httds://notquiteright.org", + "hptts:/nah", + "https;//notrightbutclose.org" + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::HTTPUrl/) } + end + end + end + + end + end +end diff --git a/spec/aliases/unixpath_spec.rb b/spec/aliases/unixpath_spec.rb new file mode 100644 index 0000000..aee161d --- /dev/null +++ b/spec/aliases/unixpath_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.5 + describe 'test::unixpath', type: :class do + describe 'valid handling' do + %w{ + /usr2/username/bin:/usr/local/bin:/usr/bin:. + /var/tmp + /Users/helencampbell/workspace/puppetlabs-stdlib + }.each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [ nil ], + [ nil, nil ], + { 'foo' => 'bar' }, + { }, + '', + "C:/whatever", + "\\var\\tmp", + "\\Users/hc/wksp/stdlib", + "*/Users//nope" + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Unixpath/) } + end + end + end + + end + end +end diff --git a/spec/aliases/windowspath_spec.rb b/spec/aliases/windowspath_spec.rb new file mode 100644 index 0000000..c13794e --- /dev/null +++ b/spec/aliases/windowspath_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.5 + describe 'test::windowspath', type: :class do + describe 'valid handling' do + %w{ + C:\\ + C:\\WINDOWS\\System32 + C:/windows/system32 + X:/foo/bar + X:\\foo\\bar + \\\\host\\windows + }.each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [ nil ], + [ nil, nil ], + { 'foo' => 'bar' }, + { }, + '', + "httds://notquiteright.org", + "/usr2/username/bin:/usr/local/bin:/usr/bin:.", + "C;//notright/here", + "C:noslashes" + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Windowspath/) } + end + end + end + + end + end +end diff --git a/spec/fixtures/test/manifests/absolutepath.pp b/spec/fixtures/test/manifests/absolutepath.pp new file mode 100644 index 0000000..8321471 --- /dev/null +++ b/spec/fixtures/test/manifests/absolutepath.pp @@ -0,0 +1,6 @@ +# Class to test the Stdlib::Absolutepath type. Not to be confused with Stdlib::Compat::Absolute_path. +class test::absolutepath( + Stdlib::Absolutepath $value, + ) { + notice("Success") +} diff --git a/spec/fixtures/test/manifests/httpsurl.pp b/spec/fixtures/test/manifests/httpsurl.pp new file mode 100644 index 0000000..9d6b92d --- /dev/null +++ b/spec/fixtures/test/manifests/httpsurl.pp @@ -0,0 +1,6 @@ +# Class to test the Stdlib::HTTPSUrl type alias +class test::httpsurl( + Stdlib::HTTPSUrl $value, + ) { + notice("Success") +} diff --git a/spec/fixtures/test/manifests/httpurl.pp b/spec/fixtures/test/manifests/httpurl.pp new file mode 100644 index 0000000..abf869e --- /dev/null +++ b/spec/fixtures/test/manifests/httpurl.pp @@ -0,0 +1,6 @@ +# Class to test the Stdlib::HTTPUrl type alias +class test::httpurl( + Stdlib::HTTPUrl $value, + ) { + notice("Success") +} diff --git a/spec/fixtures/test/manifests/unixpath.pp b/spec/fixtures/test/manifests/unixpath.pp new file mode 100644 index 0000000..9311109 --- /dev/null +++ b/spec/fixtures/test/manifests/unixpath.pp @@ -0,0 +1,6 @@ +# Class to test the Stdlib::Unixpath type alias +class test::unixpath( + Stdlib::Unixpath $value, + ) { + notice("Success") +} diff --git a/spec/fixtures/test/manifests/windowspath.pp b/spec/fixtures/test/manifests/windowspath.pp new file mode 100644 index 0000000..af93ed3 --- /dev/null +++ b/spec/fixtures/test/manifests/windowspath.pp @@ -0,0 +1,6 @@ +# Class to test the Stdlib::Windowspath type alias +class test::windowspath( + Stdlib::Windowspath $value, + ) { + notice("Success") +} diff --git a/types/absolutepath.pp b/types/absolutepath.pp new file mode 100644 index 0000000..70ec916 --- /dev/null +++ b/types/absolutepath.pp @@ -0,0 +1,2 @@ +# A strict absolutepath type +type Stdlib::Absolutepath = Variant[Stdlib::Windowspath, Stdlib::Unixpath] diff --git a/types/httpsurl.pp b/types/httpsurl.pp new file mode 100644 index 0000000..36fd30f --- /dev/null +++ b/types/httpsurl.pp @@ -0,0 +1 @@ +type Stdlib::HTTPSUrl = Pattern[/^https:\/\//] diff --git a/types/httpurl.pp b/types/httpurl.pp new file mode 100644 index 0000000..0d93a95 --- /dev/null +++ b/types/httpurl.pp @@ -0,0 +1 @@ +type Stdlib::HTTPUrl = Pattern[/^https?:\/\//] diff --git a/types/unixpath.pp b/types/unixpath.pp new file mode 100644 index 0000000..76f2c17 --- /dev/null +++ b/types/unixpath.pp @@ -0,0 +1,2 @@ +# this regex rejects any path component that is a / or a NUL +type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+(\/)?)+$/] diff --git a/types/windowspath.pp b/types/windowspath.pp new file mode 100644 index 0000000..bc1ee9c --- /dev/null +++ b/types/windowspath.pp @@ -0,0 +1 @@ +type Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/] -- cgit v1.2.3