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
9065599e
Commit
9065599e
authored
Oct 19, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a spec that generates the metadata dynamically
parent
4c4d1b79
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
+30
-0
spec/support/helpers/ci_artifact_metadata_generator.rb
spec/support/helpers/ci_artifact_metadata_generator.rb
+48
-0
No files found.
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
View file @
9065599e
...
...
@@ -112,4 +112,34 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
end
context
'generated metadata'
do
let
(
:tmpfile
)
{
Tempfile
.
new
(
'test-metadata'
)
}
let
(
:generator
)
{
CiArtifactMetadataGenerator
.
new
(
tmpfile
)
}
let
(
:entry_count
)
{
5
}
before
do
tmpfile
.
binmode
(
1
..
entry_count
).
each
do
|
index
|
generator
.
add_entry
(
"public/test-
#{
index
}
.txt"
)
end
generator
.
write
end
after
do
File
.
unlink
(
tmpfile
.
path
)
end
describe
'#find_entries!'
do
it
'reads expected number of entries'
do
stream
=
File
.
open
(
tmpfile
.
path
)
metadata
=
described_class
.
new
(
stream
,
'public'
,
{
recursive:
true
})
expect
(
metadata
.
find_entries!
.
count
).
to
eq
entry_count
end
end
end
end
spec/support/helpers/ci_artifact_metadata_generator.rb
0 → 100644
View file @
9065599e
# frozen_sting_literal: true
# This generates fake CI metadata .gz for testing
# Based off https://gitlab.com/gitlab-org/gitlab-workhorse/blob/master/internal/zipartifacts/metadata.go
class
CiArtifactMetadataGenerator
attr_accessor
:entries
,
:output
ARTIFACT_METADATA
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
.
freeze
def
initialize
(
stream
)
@entries
=
{}
@output
=
Zlib
::
GzipWriter
.
new
(
stream
)
end
def
add_entry
(
filename
)
@entries
[
filename
]
=
{
CRC
:
rand
(
0xfffffff
),
Comment
:
FFaker
::
Lorem
.
sentence
(
10
)
}
end
def
write
write_version
write_errors
write_entries
output
.
close
end
private
def
write_version
write_string
(
ARTIFACT_METADATA
)
end
def
write_errors
write_string
(
'{}'
)
end
def
write_entries
entries
.
each
do
|
filename
,
metadata
|
write_string
(
filename
)
write_string
(
metadata
.
to_json
+
"
\n
"
)
end
end
def
write_string
(
data
)
bytes
=
[
data
.
length
].
pack
(
'L>'
)
output
.
write
(
bytes
)
output
.
write
(
data
)
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