Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
92ee8c5e
Commit
92ee8c5e
authored
Jul 20, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Dir.mktmpdir instead of FileUtils.mkdir_p in the spec
parent
79983afb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
48 deletions
+56
-48
spec/services/repository_archive_clean_up_service_spec.rb
spec/services/repository_archive_clean_up_service_spec.rb
+56
-48
No files found.
spec/services/repository_archive_clean_up_service_spec.rb
View file @
92ee8c5e
...
@@ -2,16 +2,13 @@ require 'spec_helper'
...
@@ -2,16 +2,13 @@ require 'spec_helper'
describe
RepositoryArchiveCleanUpService
,
services:
true
do
describe
RepositoryArchiveCleanUpService
,
services:
true
do
describe
'#execute'
do
describe
'#execute'
do
let
(
:path
)
{
File
.
join
(
Rails
.
root
,
'tmp/tests/shared/cache/archive'
)
}
subject
(
:service
)
{
described_class
.
new
}
subject
(
:service
)
{
described_class
.
new
}
before
do
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:repository_downloads_path
).
and_return
(
path
)
end
context
'when the downloads directory does not exist'
do
context
'when the downloads directory does not exist'
do
it
'does not remove any archives'
do
it
'does not remove any archives'
do
path
=
'/invalid/path/'
stub_repository_downloads_path
(
path
)
expect
(
File
).
to
receive
(
:directory?
).
with
(
path
).
and_return
(
false
)
expect
(
File
).
to
receive
(
:directory?
).
with
(
path
).
and_return
(
false
)
expect
(
service
).
not_to
receive
(
:clean_up_old_archives
)
expect
(
service
).
not_to
receive
(
:clean_up_old_archives
)
expect
(
service
).
not_to
receive
(
:clean_up_empty_directories
)
expect
(
service
).
not_to
receive
(
:clean_up_empty_directories
)
...
@@ -21,82 +18,93 @@ describe RepositoryArchiveCleanUpService, services: true do
...
@@ -21,82 +18,93 @@ describe RepositoryArchiveCleanUpService, services: true do
end
end
context
'when the downloads directory exists'
do
context
'when the downloads directory exists'
do
before
do
FileUtils
.
mkdir_p
(
path
)
end
after
do
FileUtils
.
rm_rf
(
path
)
end
context
'when archives older than 2 hours exists'
do
context
'when archives older than 2 hours exists'
do
it
'removes old files that matches valid archive extensions'
do
it
'removes old files that matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
2
.
hours
)
stub_repository_downloads_path
(
path
)
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
2
.
hours
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
false
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
false
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
false
expect
(
File
.
directory?
(
dirname
)).
to
eq
false
end
end
end
it
'keeps old files that does not matches valid archive extensions'
do
it
'keeps old files that does not matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
2
.
hours
)
stub_repository_downloads_path
(
path
)
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
2
.
hours
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
it
'keeps old files inside invalid directories'
do
it
'keeps old files inside invalid directories'
do
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
2
.
hours
)
stub_repository_downloads_path
(
path
)
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
2
.
hours
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
end
end
context
'when archives older than 2 hours does not exist'
do
context
'when archives older than 2 hours does not exist'
do
it
'keeps files that matches valid archive extensions'
do
it
'keeps files that matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
1
.
hour
)
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
1
.
hour
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
it
'keeps files that does not matches valid archive extensions'
do
it
'keeps files that does not matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
1
.
hour
)
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
1
.
hour
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
it
'keeps files inside invalid directories'
do
it
'keeps files inside invalid directories'
do
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
Dir
.
mktmpdir
do
|
path
|
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
1
.
hour
)
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
1
.
hour
)
service
.
execute
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
end
end
end
def
create_temporary_files
(
dirname
,
extensions
,
mtime
)
def
create_temporary_files
(
dirname
,
extensions
,
mtime
)
FileUtils
.
mkdir_p
(
dirname
)
FileUtils
.
mkdir_p
(
dirname
)
FileUtils
.
touch
(
extensions
.
map
{
|
ext
|
File
.
join
(
dirname
,
"sample.
#{
ext
}
"
)
},
mtime:
Time
.
now
-
mtime
)
FileUtils
.
touch
(
extensions
.
map
{
|
ext
|
File
.
join
(
dirname
,
"sample.
#{
ext
}
"
)
},
mtime:
Time
.
now
-
mtime
)
end
end
def
stub_repository_downloads_path
(
path
)
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:repository_downloads_path
).
and_return
(
path
)
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment