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
Léo-Paul Géneau
gitlab-ce
Commits
2053d891
Commit
2053d891
authored
Jul 21, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract helper methods to clean up RepositoryArchiveCleanUpService spec
parent
92ee8c5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
66 deletions
+37
-66
spec/services/repository_archive_clean_up_service_spec.rb
spec/services/repository_archive_clean_up_service_spec.rb
+37
-66
No files found.
spec/services/repository_archive_clean_up_service_spec.rb
View file @
2053d891
...
@@ -18,93 +18,64 @@ describe RepositoryArchiveCleanUpService, services: true do
...
@@ -18,93 +18,64 @@ describe RepositoryArchiveCleanUpService, services: true do
end
end
context
'when the downloads directory exists'
do
context
'when the downloads directory exists'
do
context
'when archives older than 2 hours exists'
do
shared_examples
'invalid archive files'
do
|
dirname
,
extensions
,
mtime
|
it
'removes old files that matches valid archive extensions'
do
it
'does not remove files and directoy'
do
Dir
.
mktmpdir
do
|
path
|
in_directory_with_files
(
dirname
,
extensions
,
mtime
)
do
|
dir
,
files
|
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
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
false
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
false
end
end
it
'keeps old files that does not matches valid archive extensions'
do
Dir
.
mktmpdir
do
|
path
|
stub_repository_downloads_path
(
path
)
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
2
.
hours
)
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
it
'keeps old files inside invalid directories'
do
Dir
.
mktmpdir
do
|
path
|
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?
(
dir
name
)).
to
eq
true
expect
(
File
.
directory?
(
dir
)).
to
eq
true
end
end
end
end
end
end
context
'when archives older than 2 hours does not exist'
do
it
'removes files older than 2 hours that matches valid archive extensions'
do
it
'keeps files that matches valid archive extensions'
do
in_directory_with_files
(
'sample.git'
,
%w[tar tar.bz2 tar.gz zip]
,
2
.
hours
)
do
|
dir
,
files
|
Dir
.
mktmpdir
do
|
path
|
service
.
execute
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
1
.
hour
)
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
false
}
expect
(
File
.
directory?
(
dir
)).
to
eq
false
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
end
end
end
end
it
'keeps files that does not matches valid archive extensions'
do
context
'with files older than 2 hours that does not matches valid archive extensions'
do
Dir
.
mktmpdir
do
|
path
|
it_behaves_like
'invalid archive files'
,
'sample.git'
,
%w[conf rb]
,
2
.
hours
dirname
=
File
.
join
(
path
,
'sample.git'
)
end
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
1
.
hour
)
service
.
execute
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
context
'with files older than 2 hours inside invalid directories'
do
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
it_behaves_like
'invalid archive files'
,
'john_doe/sample.git'
,
%w[conf rb tar tar.gz]
,
2
.
hours
end
end
end
it
'keeps files inside invalid directories'
do
context
'with files newer than 2 hours that matches valid archive extensions'
do
Dir
.
mktmpdir
do
|
path
|
it_behaves_like
'invalid archive files'
,
'sample.git'
,
%w[tar tar.bz2 tar.gz zip]
,
1
.
hour
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
end
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
1
.
hour
)
service
.
execute
context
'with files newer than 2 hours that does not matches valid archive extensions'
do
it_behaves_like
'invalid archive files'
,
'sample.git'
,
%w[conf rb]
,
1
.
hour
end
files
.
each
{
|
file
|
expect
(
File
.
exist?
(
file
)).
to
eq
true
}
context
'with files newer than 2 hours inside invalid directories'
do
expect
(
File
.
directory?
(
dirname
)).
to
eq
true
it_behaves_like
'invalid archive files'
,
'sample.git'
,
%w[conf rb tar tar.gz]
,
1
.
hour
end
end
end
end
end
end
def
create_temporary_files
(
dirname
,
extensions
,
mtime
)
def
in_directory_with_files
(
dirname
,
extensions
,
mtime
)
FileUtils
.
mkdir_p
(
dirname
)
Dir
.
mktmpdir
do
|
tmpdir
|
FileUtils
.
touch
(
extensions
.
map
{
|
ext
|
File
.
join
(
dirname
,
"sample.
#{
ext
}
"
)
},
mtime:
Time
.
now
-
mtime
)
stub_repository_downloads_path
(
tmpdir
)
dir
=
File
.
join
(
tmpdir
,
dirname
)
files
=
create_temporary_files
(
dir
,
extensions
,
mtime
)
yield
(
dir
,
files
)
end
end
end
def
stub_repository_downloads_path
(
path
)
def
stub_repository_downloads_path
(
path
)
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:repository_downloads_path
).
and_return
(
path
)
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:repository_downloads_path
).
and_return
(
path
)
end
end
def
create_temporary_files
(
dir
,
extensions
,
mtime
)
FileUtils
.
mkdir_p
(
dir
)
FileUtils
.
touch
(
extensions
.
map
{
|
ext
|
File
.
join
(
dir
,
"sample.
#{
ext
}
"
)
},
mtime:
Time
.
now
-
mtime
)
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