-
Notifications
You must be signed in to change notification settings - Fork 582
Create Stdlib::File::* types #1298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ekohl
wants to merge
2
commits into
puppetlabs:main
Choose a base branch
from
ekohl:file-type-aliases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# coding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Stdlib::File::Content' do | ||
describe 'valid content' do | ||
[ | ||
'', | ||
'abc', | ||
sensitive('secret'), | ||
# TODO: test Deferred and Binary? | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.to allow_value(value) } | ||
end | ||
end | ||
|
||
context 'with garbage inputs' do | ||
[ | ||
nil, | ||
1, | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.not_to allow_value(value) } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# coding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Stdlib::File::Mode' do | ||
describe 'valid modes' do | ||
[ | ||
'7', | ||
'12', | ||
'666', | ||
|
||
'0000', | ||
'0644', | ||
'1644', | ||
'2644', | ||
'4644', | ||
'0123', | ||
'0777', | ||
|
||
'a=,o-r,u+X,g=w', | ||
'a=Xr,+0', | ||
'u=rwx,g+rX', | ||
'u+s,g-s', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.to allow_value(value) } | ||
end | ||
end | ||
end | ||
|
||
describe 'invalid modes' do | ||
context 'with garbage inputs' do | ||
[ | ||
true, | ||
false, | ||
:keyword, | ||
nil, | ||
[nil], | ||
[nil, nil], | ||
{ 'foo' => 'bar' }, | ||
{}, | ||
'', | ||
"\n0644", | ||
"\n0644\n", | ||
"0644\n", | ||
'ネット', | ||
'55555', | ||
'0x123', | ||
'0649', | ||
|
||
'=8,X', | ||
'x=r,a=wx', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.not_to allow_value(value) } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Stdlib::File::Source' do | ||
describe 'valid handling' do | ||
[ | ||
'https://hello.com', | ||
'https://notcreative.org', | ||
'https://canstillaccepthttps.co.uk', | ||
'http://anhttp.com', | ||
'http://runningoutofideas.gov', | ||
'file:///hello/bla', | ||
'file:///foo/bar.log', | ||
'puppet:///modules/foo/bar.log', | ||
'puppet://pm.example.com/modules/foo/bar.log', | ||
'puppet://192.0.2.1/modules/foo/bar.log', | ||
'/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', | ||
'puppet:///a_custom_mount_point/foo/bar/foobar.conf', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.to allow_value(value) } | ||
end | ||
end | ||
end | ||
|
||
describe 'invalid path handling' do | ||
context 'garbage inputs' do | ||
[ | ||
nil, | ||
[nil], | ||
[nil, nil], | ||
{ 'foo' => 'bar' }, | ||
{}, | ||
'', | ||
"\nfile:///foo/bar.log", | ||
"\nfile:///foo/bar.log\n", | ||
"file:///foo/bar.log\n", | ||
"\npuppet:///modules/foo/bar.log", | ||
"\npuppet:///modules/foo/bar.log\n", | ||
"puppet:///modules/foo/bar.log\n", | ||
'*/Users//nope', | ||
'\\Users/hc/wksp/stdlib', | ||
'C:noslashes', | ||
'\\var\\tmp', | ||
'puppet://[email protected]/modules/foo/bar.log', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.not_to allow_value(value) } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @summary Validate a file content attribute | ||
type Stdlib::File::Content = Variant[String, Sensitive[String], Deferred[String], Binary] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @summary Validate a file mode | ||
# See `man chmod.1` for the regular expression for symbolic mode | ||
# lint:ignore:140chars | ||
type Stdlib::File::Mode = Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/] | ||
# lint:endignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @summary Validate the source parameter on file types | ||
type Stdlib::File::Source = Variant[ | ||
Stdlib::Absolutepath, | ||
Stdlib::HTTPUrl, | ||
Pattern[ | ||
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/, | ||
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/, | ||
], | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# @summary Validate a file mode | ||
# See `man chmod.1` for the regular expression for symbolic mode | ||
# lint:ignore:140chars | ||
type Stdlib::Filemode = Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/] | ||
# lint:endignore | ||
# @deprecated Use Stdlib::File::Mode | ||
type Stdlib::Filemode = Stdlib::File::Mode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
# @summary Validate the source parameter on file types | ||
type Stdlib::Filesource = Variant[ | ||
Stdlib::Absolutepath, | ||
Stdlib::HTTPUrl, | ||
Pattern[ | ||
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/, | ||
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/, | ||
], | ||
] | ||
# @deprecated Use Stdlib::File::Source | ||
type Stdlib::Filesource = Stdlib::File::Source |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.