Skip to content

Commit ee12ea4

Browse files
authored
Merge pull request #834 from ghoneycutt/mode_type
Add Stdlib::Mode type
2 parents 1727661 + 99bbe0b commit ee12ea4

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,30 @@ Unacceptable input example:
357357
C:/whatever
358358
```
359359

360+
#### `Stdlib::Filemode`
361+
362+
Matches valid four digit modes in octal format.
363+
364+
Acceptable input examples:
365+
366+
```shell
367+
0644
368+
```
369+
370+
```shell
371+
1777
372+
```
373+
374+
Unacceptable input examples:
375+
376+
```shell
377+
644
378+
```
379+
380+
```shell
381+
0999
382+
```
383+
360384
#### `Stdlib::Windowspath`
361385

362386
Matches paths on Windows operating systems.

spec/aliases/filemode_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'test::filemode', type: :class do
5+
describe 'valid modes' do
6+
%w{
7+
0644
8+
1644
9+
2644
10+
4644
11+
0123
12+
0777
13+
}.each do |value|
14+
describe value.inspect do
15+
let(:params) {{ value: value }}
16+
it { is_expected.to compile }
17+
end
18+
end
19+
end
20+
21+
describe 'invalid modes' do
22+
context 'garbage inputs' do
23+
[
24+
nil,
25+
[ nil ],
26+
[ nil, nil ],
27+
{ 'foo' => 'bar' },
28+
{ },
29+
'',
30+
"ネット",
31+
'644',
32+
'7777',
33+
'1',
34+
'22',
35+
'333',
36+
'55555',
37+
'0x123',
38+
'0649',
39+
].each do |value|
40+
describe value.inspect do
41+
let(:params) {{ value: value }}
42+
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Filemode/) }
43+
end
44+
end
45+
end
46+
end
47+
end
48+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Filemode type alias
2+
class test::filemode (
3+
Stdlib::Filemode $value,
4+
) {
5+
notice("Success")
6+
}

types/filemode.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Filemode = Pattern[/^[0124]{1}[0-7]{3}$/]

0 commit comments

Comments
 (0)