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
e35f1607
Commit
e35f1607
authored
Nov 24, 2017
by
Zeger-Jan van de Weg
Committed by
Kamil Trzcinski
Dec 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test new artifacts for pages deploy
parent
6881d091
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
17 deletions
+93
-17
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+1
-1
spec/services/projects/update_pages_service_spec.rb
spec/services/projects/update_pages_service_spec.rb
+92
-16
No files found.
app/services/projects/update_pages_service.rb
View file @
e35f1607
...
...
@@ -18,7 +18,7 @@ module Projects
@status
.
enqueue!
@status
.
run!
raise
'missing pages artifacts'
unless
build
.
artifacts
_file
?
raise
'missing pages artifacts'
unless
build
.
artifacts?
raise
'pages are outdated'
unless
latest?
# Create temporary directory in which we will extract the artifacts
...
...
spec/services/projects/update_pages_service_spec.rb
View file @
e35f1607
require
"spec_helper"
describe
Projects
::
UpdatePagesService
do
l
et
(
:project
)
{
create
(
:project
,
:repository
)
}
l
et
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
(
'HEAD'
).
sha
)
}
l
et
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
ref:
'HEAD'
)
}
s
et
(
:project
)
{
create
(
:project
,
:repository
)
}
s
et
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
(
'HEAD'
).
sha
)
}
s
et
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
ref:
'HEAD'
)
}
let
(
:invalid_file
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
)
}
let
(
:extension
)
{
'zip'
}
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/pages.
#{
extension
}
"
)
}
let
(
:empty_file
)
{
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/pages_empty.
#{
extension
}
"
)
}
let
(
:metadata
)
do
filename
=
Rails
.
root
+
"spec/fixtures/pages.
#{
extension
}
.meta"
fixture_file_upload
(
filename
)
if
File
.
exist?
(
filename
)
end
subject
{
described_class
.
new
(
project
,
build
)
}
...
...
@@ -12,18 +20,85 @@ describe Projects::UpdatePagesService do
project
.
remove_pages
end
%w(tar.gz zip)
.
each
do
|
format
|
context
"for valid
#{
format
}
"
do
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/pages.
#{
format
}
"
)
}
let
(
:empty_file
)
{
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/pages_empty.
#{
format
}
"
)
}
let
(
:metadata
)
do
filename
=
Rails
.
root
+
"spec/fixtures/pages.
#{
format
}
.meta"
fixture_file_upload
(
filename
)
if
File
.
exist?
(
filename
)
context
'legacy artifacts'
do
%w(tar.gz zip)
.
each
do
|
format
|
let
(
:extension
)
{
format
}
context
"for valid
#{
format
}
"
do
before
do
build
.
update_attributes
(
legacy_artifacts_file:
file
)
build
.
update_attributes
(
legacy_artifacts_metadata:
metadata
)
end
describe
'pages artifacts'
do
context
'with expiry date'
do
before
do
build
.
artifacts_expire_in
=
"2 days"
end
it
"doesn't delete artifacts"
do
expect
(
execute
).
to
eq
(
:success
)
expect
(
build
.
reload
.
artifacts_file?
).
to
eq
(
true
)
end
end
context
'without expiry date'
do
it
"does delete artifacts"
do
expect
(
execute
).
to
eq
(
:success
)
expect
(
build
.
reload
.
artifacts_file?
).
to
eq
(
false
)
end
end
end
it
'succeeds'
do
expect
(
project
.
pages_deployed?
).
to
be_falsey
expect
(
execute
).
to
eq
(
:success
)
expect
(
project
.
pages_deployed?
).
to
be_truthy
# Check that all expected files are extracted
%w[index.html zero .hidden/file]
.
each
do
|
filename
|
expect
(
File
.
exist?
(
File
.
join
(
project
.
public_pages_path
,
filename
))).
to
be_truthy
end
end
it
'limits pages size'
do
stub_application_setting
(
max_pages_size:
1
)
expect
(
execute
).
not_to
eq
(
:success
)
end
it
'removes pages after destroy'
do
expect
(
PagesWorker
).
to
receive
(
:perform_in
)
expect
(
project
.
pages_deployed?
).
to
be_falsey
expect
(
execute
).
to
eq
(
:success
)
expect
(
project
.
pages_deployed?
).
to
be_truthy
project
.
destroy
expect
(
project
.
pages_deployed?
).
to
be_falsey
end
it
'fails if sha on branch is not latest'
do
build
.
update_attributes
(
ref:
'feature'
)
expect
(
execute
).
not_to
eq
(
:success
)
end
it
'fails for empty file fails'
do
build
.
update_attributes
(
legacy_artifacts_file:
empty_file
)
expect
(
execute
).
not_to
eq
(
:success
)
end
end
end
end
context
'for new artifacts'
do
context
"for a valid job"
do
before
do
build
.
update_attributes
(
legacy_artifacts_file:
file
)
build
.
update_attributes
(
legacy_artifacts_metadata:
metadata
)
create
(
:ci_job_artifact
,
file:
file
,
job:
build
)
create
(
:ci_job_artifact
,
file_type: :metadata
,
file:
metadata
,
job:
build
)
build
.
reload
end
describe
'pages artifacts'
do
...
...
@@ -35,7 +110,7 @@ describe Projects::UpdatePagesService do
it
"doesn't delete artifacts"
do
expect
(
execute
).
to
eq
(
:success
)
expect
(
build
.
reload
.
artifacts_file?
).
to
eq
(
true
)
expect
(
build
.
artifacts_file?
).
to
eq
(
true
)
end
end
...
...
@@ -74,13 +149,14 @@ describe Projects::UpdatePagesService do
end
it
'fails if sha on branch is not latest'
do
pipeline
.
update_attributes
(
sha:
'old_sha
'
)
build
.
update_attributes
(
legacy_artifacts_file:
file
)
build
.
update_attributes
(
ref:
'feature
'
)
expect
(
execute
).
not_to
eq
(
:success
)
end
it
'fails for empty file fails'
do
build
.
update_attributes
(
legacy_artifacts_file:
empty_file
)
build
.
job_archive
.
update_attributes
(
file:
empty_file
)
expect
(
execute
).
not_to
eq
(
:success
)
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