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
Jérome Perrin
gitlab-ce
Commits
4ee79839
Commit
4ee79839
authored
May 23, 2017
by
Achilleas Pipinellis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests
parent
e4d9be0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
spec/lib/gitlab/backup/manager_spec.rb
spec/lib/gitlab/backup/manager_spec.rb
+15
-14
No files found.
spec/lib/gitlab/backup/manager_spec.rb
View file @
4ee79839
...
@@ -24,10 +24,9 @@ describe Backup::Manager, lib: true do
...
@@ -24,10 +24,9 @@ describe Backup::Manager, lib: true do
describe
'#remove_old'
do
describe
'#remove_old'
do
let
(
:files
)
do
let
(
:files
)
do
[
[
'1495528448_2017_05_23_9.3.0-pre_gitlab_backup.tar'
,
'1451606400_2016_01_01_1.2.3_gitlab_backup.tar'
,
'1495528448_2017_05_23_9.3.0_gitlab_backup.tar'
,
'1451520000_2015_12_31_4.5.6_gitlab_backup.tar'
,
'1451606400_2016_01_01_gitlab_backup.tar'
,
'1451510000_2015_12_30_gitlab_backup.tar'
,
'1451520000_2015_12_31_gitlab_backup.tar'
,
'1450742400_2015_12_22_gitlab_backup.tar'
,
'1450742400_2015_12_22_gitlab_backup.tar'
,
'1449878400_gitlab_backup.tar'
,
'1449878400_gitlab_backup.tar'
,
'1449014400_gitlab_backup.tar'
,
'1449014400_gitlab_backup.tar'
,
...
@@ -39,7 +38,7 @@ describe Backup::Manager, lib: true do
...
@@ -39,7 +38,7 @@ describe Backup::Manager, lib: true do
allow
(
Dir
).
to
receive
(
:chdir
).
and_yield
allow
(
Dir
).
to
receive
(
:chdir
).
and_yield
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
files
)
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
files
)
allow
(
FileUtils
).
to
receive
(
:rm
)
allow
(
FileUtils
).
to
receive
(
:rm
)
allow
(
Time
).
to
receive
(
:now
).
and_return
(
Time
.
utc
(
201
7
))
allow
(
Time
).
to
receive
(
:now
).
and_return
(
Time
.
utc
(
201
6
))
end
end
context
'when keep_time is zero'
do
context
'when keep_time is zero'
do
...
@@ -60,6 +59,7 @@ describe Backup::Manager, lib: true do
...
@@ -60,6 +59,7 @@ describe Backup::Manager, lib: true do
context
'when there are no files older than keep_time'
do
context
'when there are no files older than keep_time'
do
before
do
before
do
# Set to 30 days
allow
(
Gitlab
.
config
.
backup
).
to
receive
(
:keep_time
).
and_return
(
2592000
)
allow
(
Gitlab
.
config
.
backup
).
to
receive
(
:keep_time
).
and_return
(
2592000
)
subject
.
remove_old
subject
.
remove_old
...
@@ -76,24 +76,24 @@ describe Backup::Manager, lib: true do
...
@@ -76,24 +76,24 @@ describe Backup::Manager, lib: true do
context
'when keep_time is set to remove files'
do
context
'when keep_time is set to remove files'
do
before
do
before
do
# Set to 1 second
allow
(
Gitlab
.
config
.
backup
).
to
receive
(
:keep_time
).
and_return
(
1
)
allow
(
Gitlab
.
config
.
backup
).
to
receive
(
:keep_time
).
and_return
(
1
)
subject
.
remove_old
subject
.
remove_old
end
end
it
'removes matching files with a human-readable versioned timestamp'
do
it
'removes matching files with a human-readable versioned timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
0
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
1
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
1
])
end
end
it
'removes matching files with a human-readable non-versioned timestamp'
do
it
'removes matching files with a human-readable non-versioned timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
2
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
end
end
it
'removes matching files without a human-readable timestamp'
do
it
'removes matching files without a human-readable timestamp'
do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
5
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
5
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
6
])
end
end
it
'does not remove files that are not old enough'
do
it
'does not remove files that are not old enough'
do
...
@@ -101,7 +101,7 @@ describe Backup::Manager, lib: true do
...
@@ -101,7 +101,7 @@ describe Backup::Manager, lib: true do
end
end
it
'does not remove non-matching files'
do
it
'does not remove non-matching files'
do
expect
(
FileUtils
).
not_to
have_received
(
:rm
).
with
(
files
[
7
])
expect
(
FileUtils
).
not_to
have_received
(
:rm
).
with
(
files
[
6
])
end
end
it
'prints a done message'
do
it
'prints a done message'
do
...
@@ -124,10 +124,11 @@ describe Backup::Manager, lib: true do
...
@@ -124,10 +124,11 @@ describe Backup::Manager, lib: true do
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
2
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
2
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
3
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
4
])
expect
(
FileUtils
).
to
have_received
(
:rm
).
with
(
files
[
5
])
end
end
it
'sets the correct removed count'
do
it
'sets the correct removed count'
do
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
3
removed)'
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
'done. (
4
removed)'
)
end
end
it
'prints the error from file that could not be removed'
do
it
'prints the error from file that could not be removed'
do
...
@@ -157,7 +158,7 @@ describe Backup::Manager, lib: true do
...
@@ -157,7 +158,7 @@ describe Backup::Manager, lib: true do
before
do
before
do
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
[
[
'1451606400_2016_01_01_gitlab_backup.tar'
,
'1451606400_2016_01_01_
1.2.3_
gitlab_backup.tar'
,
'1451520000_2015_12_31_gitlab_backup.tar'
'1451520000_2015_12_31_gitlab_backup.tar'
]
]
)
)
...
@@ -194,21 +195,21 @@ describe Backup::Manager, lib: true do
...
@@ -194,21 +195,21 @@ describe Backup::Manager, lib: true do
before
do
before
do
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
allow
(
Dir
).
to
receive
(
:glob
).
and_return
(
[
[
'1451606400_2016_01_01_gitlab_backup.tar'
'1451606400_2016_01_01_
1.2.3_
gitlab_backup.tar'
]
]
)
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
Kernel
).
to
receive
(
:system
).
and_return
(
true
)
allow
(
Kernel
).
to
receive
(
:system
).
and_return
(
true
)
allow
(
YAML
).
to
receive
(
:load_file
).
and_return
(
gitlab_version:
Gitlab
::
VERSION
)
allow
(
YAML
).
to
receive
(
:load_file
).
and_return
(
gitlab_version:
Gitlab
::
VERSION
)
stub_env
(
'BACKUP'
,
'1451606400_2016_01_01'
)
stub_env
(
'BACKUP'
,
'1451606400_2016_01_01
_1.2.3
'
)
end
end
it
'unpacks the file'
do
it
'unpacks the file'
do
subject
.
unpack
subject
.
unpack
expect
(
Kernel
).
to
have_received
(
:system
)
expect
(
Kernel
).
to
have_received
(
:system
)
.
with
(
"tar"
,
"-xf"
,
"1451606400_2016_01_01_gitlab_backup.tar"
)
.
with
(
"tar"
,
"-xf"
,
"1451606400_2016_01_01_
1.2.3_
gitlab_backup.tar"
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
a_string_matching
(
'done'
))
expect
(
progress
).
to
have_received
(
:puts
).
with
(
a_string_matching
(
'done'
))
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