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
d4290995
Commit
d4290995
authored
Apr 06, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Trace::Stream
parent
b94c84e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
343 additions
and
205 deletions
+343
-205
app/models/ci/job_trace_chunk.rb
app/models/ci/job_trace_chunk.rb
+1
-1
spec/lib/gitlab/ci/trace/stream_spec.rb
spec/lib/gitlab/ci/trace/stream_spec.rb
+342
-204
No files found.
app/models/ci/job_trace_chunk.rb
View file @
d4290995
...
...
@@ -24,7 +24,7 @@ module Ci
raw_data
else
raise
'Unsupported data store'
end
end
&
.
force_encoding
(
Encoding
::
BINARY
)
end
def
set_data
(
value
)
...
...
spec/lib/gitlab/ci/trace/stream_spec.rb
View file @
d4290995
require
'spec_helper'
describe
Gitlab
::
Ci
::
Trace
::
Stream
do
describe
Gitlab
::
Ci
::
Trace
::
Stream
,
:clean_gitlab_redis_cache
do
set
(
:job
)
{
create
(
:ci_build
,
:running
)
}
before
do
stub_feature_flags
(
ci_enable_live_trace:
true
)
end
describe
'delegates'
do
subject
{
described_class
.
new
{
nil
}
}
...
...
@@ -15,12 +21,7 @@ describe Gitlab::Ci::Trace::Stream do
end
describe
'#limit'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
((
1
..
8
).
to_a
.
join
(
"
\n
"
))
end
end
shared_examples_for
'limits'
do
it
'if size is larger we start from beginning'
do
stream
.
limit
(
20
)
...
...
@@ -70,21 +71,32 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#append'
do
let
(
:tempfile
)
{
Tempfile
.
new
}
context
'when stream is StringIO'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
((
1
..
8
).
to_a
.
join
(
"
\n
"
))
end
end
it_behaves_like
'limits'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
tempfile
.
write
(
"12345678"
)
tempfile
.
rewind
tempfile
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
((
1
..
8
).
to_a
.
join
(
"
\n
"
))
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
after
do
tempfile
.
unlink
it_behaves_like
'limits'
end
end
describe
'#append'
do
shared_examples_for
'appends'
do
it
"truncates and append content"
do
stream
.
append
(
"89"
,
4
)
stream
.
seek
(
0
)
...
...
@@ -105,13 +117,40 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#set'
do
context
'when stream is StringIO'
do
let
(
:tempfile
)
{
Tempfile
.
new
}
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
(
"12345678"
)
tempfile
.
write
(
"12345678"
)
tempfile
.
rewind
tempfile
end
end
after
do
tempfile
.
unlink
end
it_behaves_like
'appends'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
'12345678'
)
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'appends'
end
end
describe
'#set'
do
shared_examples_for
'sets'
do
before
do
stream
.
set
(
"8901"
)
end
...
...
@@ -124,15 +163,32 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#raw'
do
let
(
:path
)
{
__FILE__
}
let
(
:lines
)
{
File
.
readlines
(
path
)
}
context
'when stream is StringIO'
do
let
(
:stream
)
do
described_class
.
new
do
File
.
open
(
path
)
StringIO
.
new
(
"12345678"
)
end
end
it_behaves_like
'sets'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
'12345678'
)
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'sets'
end
end
describe
'#raw'
do
shared_examples_for
'sets'
do
it
'returns all contents if last_lines is not specified'
do
result
=
stream
.
raw
...
...
@@ -163,13 +219,33 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#html_with_state'
do
let
(
:path
)
{
__FILE__
}
let
(
:lines
)
{
File
.
readlines
(
path
)
}
context
'when stream is File'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
(
"1234"
)
File
.
open
(
path
)
end
end
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
File
.
binread
(
path
))
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'sets'
end
end
describe
'#html_with_state'
do
shared_examples_for
'html_with_states'
do
it
'returns html content with state'
do
result
=
stream
.
html_with_state
...
...
@@ -193,13 +269,32 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#html
'
do
context
'when stream is StringIO
'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
(
"12
\n
34
\n
56"
)
StringIO
.
new
(
"1234"
)
end
end
it_behaves_like
'html_with_states'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
"1234"
)
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'html_with_states'
end
end
describe
'#html'
do
shared_examples_for
'htmls'
do
it
"returns html"
do
expect
(
stream
.
html
).
to
eq
(
"12<br>34<br>56"
)
end
...
...
@@ -209,15 +304,32 @@ describe Gitlab::Ci::Trace::Stream do
end
end
describe
'#extract_coverage
'
do
context
'when stream is StringIO
'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
(
data
)
StringIO
.
new
(
"12
\n
34
\n
56"
)
end
end
subject
{
stream
.
extract_coverage
(
regex
)
}
it_behaves_like
'htmls'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
"12
\n
34
\n
56"
)
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'htmls'
end
end
describe
'#extract_coverage'
do
shared_examples_for
'extract_coverages'
do
context
'valid content & regex'
do
let
(
:data
)
{
'Coverage 1033 / 1051 LOC (98.29%) covered'
}
let
(
:regex
)
{
'\(\d+.\d+\%\) covered'
}
...
...
@@ -344,4 +456,30 @@ describe Gitlab::Ci::Trace::Stream do
end
end
end
subject
{
stream
.
extract_coverage
(
regex
)
}
context
'when stream is StringIO'
do
let
(
:stream
)
do
described_class
.
new
do
StringIO
.
new
(
data
)
end
end
it_behaves_like
'extract_coverages'
end
context
'when stream is ChunkedIO'
do
let
(
:stream
)
do
described_class
.
new
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
).
tap
do
|
chunked_io
|
chunked_io
.
write
(
data
)
chunked_io
.
seek
(
0
,
IO
::
SEEK_SET
)
end
end
end
it_behaves_like
'extract_coverages'
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