Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
d9d15d36
Commit
d9d15d36
authored
8 years ago
by
Markus Reiter
Browse files
Options
Downloads
Patches
Plain Diff
Convert `Pkg` test to spec.
parent
17fd7d6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/cask/spec/cask/pkg_spec.rb
+114
-0
114 additions, 0 deletions
Library/Homebrew/cask/spec/cask/pkg_spec.rb
Library/Homebrew/cask/spec/spec_helper.rb
+8
-0
8 additions, 0 deletions
Library/Homebrew/cask/spec/spec_helper.rb
with
122 additions
and
0 deletions
Library/Homebrew/cask/
test
/cask/pkg_
test
.rb
→
Library/Homebrew/cask/
spec
/cask/pkg_
spec
.rb
+
114
−
0
View file @
d9d15d36
require
"
test
_helper"
require
"
spec
_helper"
describe
Hbc
::
Pkg
do
describe
"uninstall"
do
it
"removes files and dirs referenced by the pkg"
do
pkg
=
Hbc
::
Pkg
.
new
(
"my.fake.pkg"
,
Hbc
::
NeverSudoSystemCommand
)
let
(
:fake_system_command
)
{
Hbc
::
NeverSudoSystemCommand
}
let
(
:empty_response
)
{
double
(
stdout:
""
)
}
let
(
:pkg
)
{
described_class
.
new
(
"my.fake.pkg"
,
fake_system_command
)
}
it
"removes files and dirs referenced by the pkg"
do
some_files
=
Array
.
new
(
3
)
{
Pathname
.
new
(
Tempfile
.
new
(
"testfile"
).
path
)
}
pkg
.
stubs
(
:pkgutil_bom_files
).
return
s
some_files
allow
(
pkg
).
to
receive
(
:pkgutil_bom_files
).
and_
return
(
some_files
)
some_specials
=
Array
.
new
(
3
)
{
Pathname
.
new
(
Tempfile
.
new
(
"testfile"
).
path
)
}
pkg
.
stubs
(
:pkgutil_bom_specials
).
return
s
some_specials
allow
(
pkg
).
to
receive
(
:pkgutil_bom_specials
).
and_
return
(
some_specials
)
some_dirs
=
Array
.
new
(
3
)
{
Pathname
.
new
(
Dir
.
mktmpdir
)
}
pkg
.
stubs
(
:pkgutil_bom_dirs
).
return
s
some_dirs
allow
(
pkg
).
to
receive
(
:pkgutil_bom_dirs
).
and_
return
(
some_dirs
)
pkg
.
stubs
(
:forget
)
allow
(
pkg
).
to
receive
(
:forget
)
pkg
.
uninstall
some_files
.
each
do
|
file
|
file
.
wont_be
:
exist
?
expect
(
file
).
not_to
exist
end
some_dirs
.
each
do
|
dir
|
dir
.
wont_be
:
exist
?
expect
(
dir
).
not_to
exist
end
end
it
"forgets the pkg
"
do
pkg
=
Hbc
::
Pkg
.
new
(
"my.fake.pkg"
,
Hbc
::
Fake
SystemCommand
)
context
"pkgutil
"
do
let
(
:fake_system_command
)
{
class_double
(
Hbc
::
SystemCommand
)
}
Hbc
::
FakeSystemCommand
.
stubs_command
(
[
"/usr/sbin/pkgutil"
,
"--only-files"
,
"--files"
,
"my.fake.pkg"
]
)
Hbc
::
FakeSystemCommand
.
stubs_command
(
[
"/usr/sbin/pkgutil"
,
"--only-dirs"
,
"--files"
,
"my.fake.pkg"
]
)
Hbc
::
FakeSystemCommand
.
stubs_command
(
[
"/usr/sbin/pkgutil"
,
"--files"
,
"my.fake.pkg"
]
)
it
"forgets the pkg"
do
allow
(
fake_system_command
).
to
receive
(
:run!
).
with
(
"/usr/sbin/pkgutil"
,
args:
[
"--only-files"
,
"--files"
,
"my.fake.pkg"
]
).
and_return
(
empty_response
)
Hbc
::
FakeSystemCommand
.
expects_command
(
[
"/usr/bin/sudo"
,
"-E"
,
"--"
,
"/usr/sbin/pkgutil"
,
"--forget"
,
"my.fake.pkg"
]
)
allow
(
fake_system_command
).
to
receive
(
:run!
).
with
(
"/usr/sbin/pkgutil"
,
args:
[
"--only-dirs"
,
"--files"
,
"my.fake.pkg"
]
).
and_return
(
empty_response
)
pkg
.
uninstall
end
allow
(
fake_system_command
).
to
receive
(
:run!
).
with
(
"/usr/sbin/pkgutil"
,
args:
[
"--files"
,
"my.fake.pkg"
]
).
and_return
(
empty_response
)
expect
(
fake_system_command
).
to
receive
(
:run!
).
with
(
"/usr/sbin/pkgutil"
,
args:
[
"--forget"
,
"my.fake.pkg"
],
sudo:
true
)
it
"cleans broken symlinks, but leaves AOK symlinks"
do
pkg
=
Hbc
::
Pkg
.
new
(
"my.fake.pkg"
,
Hbc
::
NeverSudoSystemCommand
)
pkg
.
uninstall
end
end
it
"removes broken symlinks"
do
fake_dir
=
Pathname
.
new
(
Dir
.
mktmpdir
)
fake_file
=
fake_dir
.
join
(
"ima_file"
).
tap
{
|
path
|
FileUtils
.
touch
(
path
)
}
intact_symlink
=
fake_dir
.
join
(
"intact_symlink"
).
tap
{
|
path
|
path
.
make_symlink
(
fake_file
)
}
broken_symlink
=
fake_dir
.
join
(
"broken_symlink"
).
tap
{
|
path
|
path
.
make_symlink
(
"im_nota_file"
)
}
pkg
.
stubs
(
:pkgutil_bom_specials
).
return
s
([])
pkg
.
stubs
(
:pkgutil_bom_files
).
return
s
([])
pkg
.
stubs
(
:pkgutil_bom_dirs
).
return
s
([
fake_dir
])
pkg
.
stubs
(
:forget
)
allow
(
pkg
).
to
receive
(
:pkgutil_bom_specials
).
and_
return
([])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_files
).
and_
return
([])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_dirs
).
and_
return
([
fake_dir
])
allow
(
pkg
).
to
receive
(
:forget
)
pkg
.
uninstall
intact_symlink
.
must_be
:
exist
?
broken_symlink
.
wont_be
:
exist
?
fake_dir
.
must_be
:
exist
?
expect
(
intact_symlink
).
to
exist
expect
(
broken_symlink
).
not_to
exist
expect
(
fake_dir
).
to
exist
end
it
"cleans files incorrectly reported as directories"
do
pkg
=
Hbc
::
Pkg
.
new
(
"my.fake.pkg"
,
Hbc
::
NeverSudoSystemCommand
)
it
"removes files incorrectly reportes as directories"
do
fake_dir
=
Pathname
.
new
(
Dir
.
mktmpdir
)
fake_file
=
fake_dir
.
join
(
"ima_file_pretending_to_be_a_dir"
).
tap
{
|
path
|
FileUtils
.
touch
(
path
)
}
pkg
.
stubs
(
:pkgutil_bom_specials
).
return
s
([])
pkg
.
stubs
(
:pkgutil_bom_files
).
return
s
([])
pkg
.
stubs
(
:pkgutil_bom_dirs
).
return
s
([
fake_file
,
fake_dir
])
pkg
.
stubs
(
:forget
)
allow
(
pkg
).
to
receive
(
:pkgutil_bom_specials
).
and_
return
([])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_files
).
and_
return
([])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_dirs
).
and_
return
([
fake_file
,
fake_dir
])
allow
(
pkg
).
to
receive
(
:forget
)
pkg
.
uninstall
fake_file
.
wont_be
:
exist
?
fake_dir
.
wont_be
:
exist
?
expect
(
fake_file
).
not_to
exist
expect
(
fake_dir
).
not_to
exist
end
it
"snags permissions on ornery dirs, but returns them afterwords"
do
pkg
=
Hbc
::
Pkg
.
new
(
"my.fake.pkg"
,
Hbc
::
NeverSudoSystemCommand
)
it
"snags permissions on ornery dirs, but returns them afterwards"
do
fake_dir
=
Pathname
.
new
(
Dir
.
mktmpdir
)
fake_file
=
fake_dir
.
join
(
"ima_installed_file"
).
tap
{
|
path
|
FileUtils
.
touch
(
path
)
}
fake_dir
.
chmod
(
0000
)
pkg
.
stubs
(
:pkgutil_bom_specials
).
return
s
([])
pkg
.
stubs
(
:pkgutil_bom_files
).
return
s
([
fake_file
])
pkg
.
stubs
(
:pkgutil_bom_dirs
).
return
s
([
fake_dir
])
pkg
.
stubs
(
:forget
)
allow
(
pkg
).
to
receive
(
:pkgutil_bom_specials
).
and_
return
([])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_files
).
and_
return
([
fake_file
])
allow
(
pkg
).
to
receive
(
:pkgutil_bom_dirs
).
and_
return
([
fake_dir
])
allow
(
pkg
).
to
receive
(
:forget
)
shutup
do
pkg
.
uninstall
end
fake_dir
.
must_be
:
directory
?
fake_file
.
wont_be
:
file
?
(
fake_dir
.
stat
.
mode
%
01000
).
to_s
(
8
)
.
must_equal
"0"
expect
(
fake_dir
).
to
be_a_
directory
expect
(
fake_file
).
not_to
be_a_
file
expect
(
(
fake_dir
.
stat
.
mode
%
01000
).
to_s
(
8
)
).
to
eq
(
"0"
)
end
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/cask/spec/spec_helper.rb
+
8
−
0
View file @
d9d15d36
...
...
@@ -41,3 +41,11 @@ RSpec.configure do |config|
]
end
end
module
Hbc
class
NeverSudoSystemCommand
<
SystemCommand
def
self
.
run
(
command
,
options
=
{})
super
(
command
,
options
.
merge
(
sudo:
false
))
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment