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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
66d5cb7a
Commit
66d5cb7a
authored
Jan 30, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add essential tests
parent
a8b11189
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
240 additions
and
0 deletions
+240
-0
app/uploaders/job_artifact_uploader.rb
app/uploaders/job_artifact_uploader.rb
+6
-0
spec/factories/ci/job_artifacts.rb
spec/factories/ci/job_artifacts.rb
+9
-0
spec/fixtures/trace/sample_trace
spec/fixtures/trace/sample_trace
+18
-0
spec/lib/gitlab/ci/trace_spec.rb
spec/lib/gitlab/ci/trace_spec.rb
+87
-0
spec/models/ci/job_artifact_spec.rb
spec/models/ci/job_artifact_spec.rb
+3
-0
spec/services/ci/create_trace_artifact_service_spec.rb
spec/services/ci/create_trace_artifact_service_spec.rb
+43
-0
spec/uploaders/job_artifact_uploader_spec.rb
spec/uploaders/job_artifact_uploader_spec.rb
+43
-0
spec/workers/build_finished_worker_spec.rb
spec/workers/build_finished_worker_spec.rb
+2
-0
spec/workers/create_trace_artifact_worker_spec.rb
spec/workers/create_trace_artifact_worker_spec.rb
+29
-0
No files found.
app/uploaders/job_artifact_uploader.rb
View file @
66d5cb7a
...
...
@@ -22,6 +22,12 @@ class JobArtifactUploader < GitlabUploader
end
end
def
filename
return
'trace.log'
if
model
.
trace?
super
end
private
def
dynamic_segment
...
...
spec/factories/ci/job_artifacts.rb
View file @
66d5cb7a
...
...
@@ -30,5 +30,14 @@ FactoryBot.define do
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts_metadata.gz'
),
'application/x-gzip'
)
end
end
trait
:trace
do
file_type
:trace
after
(
:build
)
do
|
artifact
,
evaluator
|
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/trace/sample_trace'
),
'text/plain'
)
end
end
end
end
spec/fixtures/trace/sample_trace
0 → 100644
View file @
66d5cb7a
[0KRunning with gitlab-runner 10.0.2 (a9a76a50)
on ShinyaMaedas-MacBook-Pro.local (e1e5600d)
[0;m[0KUsing Docker executor with image ruby:2.1 ...
[0;m[0KUsing docker image sha256:35c04f14f9926d1c8c68927cb43f69435fda36ecbaa3ca6f92218205363a2b99 for predefined container...
[0;m[0KPulling docker image ruby:2.1 ...
[0;m[0KUsing docker image ruby:2.1 ID=sha256:223d1eaa9523fa64e78f5a92b701c9c11cbc507f0ff62246dbbacdae395ffea3 for build container...
[0;mRunning on runner-e1e5600d-project-12-concurrent-0 via ShinyaMaedas-MacBook-Pro.local...
[32;1mFetching changes...[0;m
Removing hoge.txt
HEAD is now at bc8d55a Update .gitlab-ci.yml
[32;1mChecking out bc8d55ab as master...[0;m
[32;1mSkipping Git submodules setup[0;m
[32;1m$ echo "hoge" >> hoge.txt[0;m
[32;1mUploading artifacts...[0;m
hoge.txt: found 1 matching files [0;m
Uploading artifacts to coordinator... ok [0;m id[0;m=1045 responseStatus[0;m=201 Created token[0;m=c1uexKnX
[32;1mJob succeeded
[0;m
\ No newline at end of file
spec/lib/gitlab/ci/trace_spec.rb
View file @
66d5cb7a
...
...
@@ -238,11 +238,98 @@ describe Gitlab::Ci::Trace do
end
end
describe
'#read'
do
shared_examples
'read successfully with IO'
do
it
'yields with source'
do
trace
.
read
do
|
stream
|
expect
(
stream
).
to
be_a
(
Gitlab
::
Ci
::
Trace
::
Stream
)
expect
(
stream
.
stream
).
to
be_a
(
IO
)
end
end
end
shared_examples
'read successfully with StringIO'
do
it
'yields with source'
do
trace
.
read
do
|
stream
|
expect
(
stream
).
to
be_a
(
Gitlab
::
Ci
::
Trace
::
Stream
)
expect
(
stream
.
stream
).
to
be_a
(
StringIO
)
end
end
end
shared_examples
'failed to read'
do
it
'yields without source'
do
trace
.
read
do
|
stream
|
expect
(
stream
).
to
be_a
(
Gitlab
::
Ci
::
Trace
::
Stream
)
expect
(
stream
.
stream
).
to
be_nil
end
end
end
context
'when trace artifact exists'
do
before
do
create
(
:ci_job_artifact
,
:trace
,
job:
build
)
end
it_behaves_like
'read successfully with IO'
end
context
'when current_path (with project_id) exists'
do
before
do
expect
(
trace
).
to
receive
(
:default_path
)
{
expand_fixture_path
(
'trace/sample_trace'
)
}
end
it_behaves_like
'read successfully with IO'
end
context
'when current_path (with project_ci_id) exists'
do
before
do
expect
(
trace
).
to
receive
(
:deprecated_path
)
{
expand_fixture_path
(
'trace/sample_trace'
)
}
end
it_behaves_like
'read successfully with IO'
end
context
'when db trace exists'
do
before
do
build
.
send
(
:write_attribute
,
:trace
,
"data"
)
end
it_behaves_like
'read successfully with StringIO'
end
context
'when no sources exist'
do
it_behaves_like
'failed to read'
end
end
describe
'trace handling'
do
subject
{
trace
.
exist?
}
context
'trace does not exist'
do
it
{
expect
(
trace
.
exist?
).
to
be
(
false
)
}
end
context
'when trace artifact exists'
do
before
do
create
(
:ci_job_artifact
,
:trace
,
job:
build
)
end
it
{
is_expected
.
to
be_truthy
}
context
'when the trace artifact has been erased'
do
before
do
trace
.
erase!
end
it
{
is_expected
.
to
be_falsy
}
it
'removes associations'
do
expect
(
Ci
::
JobArtifact
.
exists?
(
job_id:
build
.
id
,
file_type: :trace
)).
to
be_falsy
end
end
end
context
'new trace path is used'
do
before
do
trace
.
send
(
:ensure_directory
)
...
...
spec/models/ci/job_artifact_spec.rb
View file @
66d5cb7a
...
...
@@ -12,6 +12,9 @@ describe Ci::JobArtifact do
it
{
is_expected
.
to
respond_to
(
:created_at
)
}
it
{
is_expected
.
to
respond_to
(
:updated_at
)
}
it
{
is_expected
.
to
delegate_method
(
:open
).
to
(
:file
)
}
it
{
is_expected
.
to
delegate_method
(
:exists?
).
to
(
:file
)
}
describe
'callbacks'
do
subject
{
create
(
:ci_job_artifact
,
:archive
)
}
...
...
spec/services/ci/create_trace_artifact_service_spec.rb
0 → 100644
View file @
66d5cb7a
require
'spec_helper'
describe
Ci
::
CreateTraceArtifactService
do
describe
'#execute'
do
subject
{
described_class
.
new
(
nil
,
nil
).
execute
(
job
)
}
let
(
:job
)
{
create
(
:ci_build
)
}
context
'when the job does not have trace artifact'
do
context
'when the job has a trace file'
do
before
do
allow_any_instance_of
(
Gitlab
::
Ci
::
Trace
)
.
to
receive
(
:default_path
)
{
expand_fixture_path
(
'trace/sample_trace'
)
}
allow_any_instance_of
(
JobArtifactUploader
).
to
receive
(
:move_to_cache
)
{
false
}
allow_any_instance_of
(
JobArtifactUploader
).
to
receive
(
:move_to_store
)
{
false
}
end
it
'creates trace artifact'
do
expect
{
subject
}.
to
change
{
Ci
::
JobArtifact
.
count
}.
by
(
1
)
expect
(
job
.
job_artifacts_trace
.
read_attribute
(
:file
)).
to
eq
(
'trace.log'
)
end
context
'when the job has already had trace artifact'
do
before
do
create
(
:ci_job_artifact
,
:trace
,
job:
job
)
end
it
'does not create trace artifact'
do
expect
{
subject
}.
not_to
change
{
Ci
::
JobArtifact
.
count
}
end
end
end
context
'when the job does not have a trace file'
do
it
'does not create trace artifact'
do
expect
{
subject
}.
not_to
change
{
Ci
::
JobArtifact
.
count
}
end
end
end
end
end
spec/uploaders/job_artifact_uploader_spec.rb
View file @
66d5cb7a
...
...
@@ -23,6 +23,49 @@ describe JobArtifactUploader do
store_dir:
%r[
\h
{2}/
\h
{2}/
\h
{64}/
\d
{4}_
\d
{1,2}_
\d
{1,2}/
\d
+/
\d
+
\z
]
end
describe
'#open'
do
subject
{
uploader
.
open
}
context
'when trace is stored in File storage'
do
context
'when file exists'
do
let
(
:file
)
do
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/trace/sample_trace'
),
'text/plain'
)
end
before
do
uploader
.
store!
(
file
)
end
it
'returns io stream'
do
is_expected
.
to
be_a
(
IO
)
end
end
context
'when file does not exist'
do
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
end
end
describe
'#filename'
do
subject
{
uploader
.
filename
}
context
'when artifact file_type is archive'
do
let
(
:job_artifact
)
{
create
(
:ci_job_artifact
,
:archive
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when artifact file_type is trace'
do
let
(
:job_artifact
)
{
create
(
:ci_job_artifact
,
:trace
)
}
it
{
is_expected
.
to
eq
(
'trace.log'
)
}
end
end
context
'file is stored in valid local_path'
do
let
(
:file
)
do
fixture_file_upload
(
...
...
spec/workers/build_finished_worker_spec.rb
View file @
66d5cb7a
...
...
@@ -13,6 +13,8 @@ describe BuildFinishedWorker do
expect
(
BuildTraceSectionsWorker
)
.
to
receive
(
:perform_async
)
expect
(
CreateTraceArtifactWorker
)
.
to
receive
(
:perform_async
)
expect_any_instance_of
(
BuildCoverageWorker
)
.
to
receive
(
:perform
)
expect_any_instance_of
(
BuildHooksWorker
)
...
...
spec/workers/create_trace_artifact_worker_spec.rb
0 → 100644
View file @
66d5cb7a
require
'spec_helper'
describe
CreateTraceArtifactWorker
do
describe
'#perform'
do
subject
{
described_class
.
new
.
perform
(
job
)
}
context
'when job is found'
do
let
(
:job
)
{
create
(
:ci_build
)
}
it
'executes service'
do
expect_any_instance_of
(
Ci
::
CreateTraceArtifactService
)
.
to
receive
(
:execute
)
subject
end
end
context
'when job is not found'
do
let
(
:job
)
{
nil
}
it
'does not execute service'
do
expect_any_instance_of
(
Ci
::
CreateTraceArtifactService
)
.
not_to
receive
(
:execute
)
subject
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