Skip to content

Commit 02b42fd

Browse files
committed
Create Stdlib::File::* types
Previously these were prefixed, but this creates an explicit namespace.
1 parent 03bcefd commit 02b42fd

File tree

6 files changed

+143
-12
lines changed

6 files changed

+143
-12
lines changed

spec/type_aliases/file_mode_spec.rb

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# coding: utf-8
2+
# frozen_string_literal: true
3+
4+
require 'spec_helper'
5+
6+
describe 'Stdlib::File::Mode' do
7+
describe 'valid modes' do
8+
[
9+
'7',
10+
'12',
11+
'666',
12+
13+
'0000',
14+
'0644',
15+
'1644',
16+
'2644',
17+
'4644',
18+
'0123',
19+
'0777',
20+
21+
'a=,o-r,u+X,g=w',
22+
'a=Xr,+0',
23+
'u=rwx,g+rX',
24+
'u+s,g-s',
25+
].each do |value|
26+
describe value.inspect do
27+
it { is_expected.to allow_value(value) }
28+
end
29+
end
30+
end
31+
32+
describe 'invalid modes' do
33+
context 'with garbage inputs' do
34+
[
35+
true,
36+
false,
37+
:keyword,
38+
nil,
39+
[nil],
40+
[nil, nil],
41+
{ 'foo' => 'bar' },
42+
{},
43+
'',
44+
"\n0644",
45+
"\n0644\n",
46+
"0644\n",
47+
'ネット',
48+
'55555',
49+
'0x123',
50+
'0649',
51+
52+
'=8,X',
53+
'x=r,a=wx',
54+
].each do |value|
55+
describe value.inspect do
56+
it { is_expected.not_to allow_value(value) }
57+
end
58+
end
59+
end
60+
end
61+
end

spec/type_aliases/file_source_spec.rb

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Stdlib::File::Source' do
6+
describe 'valid handling' do
7+
[
8+
'https://hello.com',
9+
'https://notcreative.org',
10+
'https://canstillaccepthttps.co.uk',
11+
'http://anhttp.com',
12+
'http://runningoutofideas.gov',
13+
'file:///hello/bla',
14+
'file:///foo/bar.log',
15+
'puppet:///modules/foo/bar.log',
16+
'puppet://pm.example.com/modules/foo/bar.log',
17+
'puppet://192.0.2.1/modules/foo/bar.log',
18+
'/usr2/username/bin:/usr/local/bin:/usr/bin:.',
19+
'C:/',
20+
'C:\\',
21+
'C:\\WINDOWS\\System32',
22+
'C:/windows/system32',
23+
'X:/foo/bar',
24+
'X:\\foo\\bar',
25+
'\\\\host\\windows',
26+
'//host/windows',
27+
'/var/tmp',
28+
'/var/opt/../lib/puppet',
29+
'puppet:///a_custom_mount_point/foo/bar/foobar.conf',
30+
].each do |value|
31+
describe value.inspect do
32+
it { is_expected.to allow_value(value) }
33+
end
34+
end
35+
end
36+
37+
describe 'invalid path handling' do
38+
context 'garbage inputs' do
39+
[
40+
nil,
41+
[nil],
42+
[nil, nil],
43+
{ 'foo' => 'bar' },
44+
{},
45+
'',
46+
"\nfile:///foo/bar.log",
47+
"\nfile:///foo/bar.log\n",
48+
"file:///foo/bar.log\n",
49+
"\npuppet:///modules/foo/bar.log",
50+
"\npuppet:///modules/foo/bar.log\n",
51+
"puppet:///modules/foo/bar.log\n",
52+
'*/Users//nope',
53+
'\\Users/hc/wksp/stdlib',
54+
'C:noslashes',
55+
'\\var\\tmp',
56+
'puppet://[email protected]/modules/foo/bar.log',
57+
].each do |value|
58+
describe value.inspect do
59+
it { is_expected.not_to allow_value(value) }
60+
end
61+
end
62+
end
63+
end
64+
end

types/file/mode.pp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @summary Validate a file mode
2+
# See `man chmod.1` for the regular expression for symbolic mode
3+
# lint:ignore:140chars
4+
type Stdlib::File::Mode = Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/]
5+
# lint:endignore

types/file/source.pp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @summary Validate the source parameter on file types
2+
type Stdlib::File::Source = Variant[
3+
Stdlib::Absolutepath,
4+
Stdlib::HTTPUrl,
5+
Pattern[
6+
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/,
7+
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/,
8+
],
9+
]

types/filemode.pp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# @summary Validate a file mode
2-
# See `man chmod.1` for the regular expression for symbolic mode
3-
# lint:ignore:140chars
4-
type Stdlib::Filemode = Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/]
5-
# lint:endignore
2+
# @deprecated Use Stdlib::File::Mode
3+
type Stdlib::Filemode = Stdlib::File::Mode

types/filesource.pp

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
# @summary Validate the source parameter on file types
2-
type Stdlib::Filesource = Variant[
3-
Stdlib::Absolutepath,
4-
Stdlib::HTTPUrl,
5-
Pattern[
6-
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/,
7-
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/,
8-
],
9-
]
2+
# @deprecated Use Stdlib::File::Source
3+
type Stdlib::Filesource = Stdlib::File::Source

0 commit comments

Comments
 (0)