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
38c61ab6
Commit
38c61ab6
authored
Nov 23, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs failures, and use factory with `:ci_job_artifact, :archive`
parent
871de0f1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
94 additions
and
26 deletions
+94
-26
app/uploaders/job_artifact_uploader.rb
app/uploaders/job_artifact_uploader.rb
+18
-2
app/uploaders/legacy_artifact_uploader.rb
app/uploaders/legacy_artifact_uploader.rb
+1
-1
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+2
-2
spec/factories/ci/job_artifacts.rb
spec/factories/ci/job_artifacts.rb
+15
-13
spec/migrations/migrate_old_artifacts_spec.rb
spec/migrations/migrate_old_artifacts_spec.rb
+1
-1
spec/models/ci/job_artifact_spec.rb
spec/models/ci/job_artifact_spec.rb
+1
-1
spec/models/project_statistics_spec.rb
spec/models/project_statistics_spec.rb
+1
-1
spec/uploaders/job_artifact_uploader_spec.rb
spec/uploaders/job_artifact_uploader_spec.rb
+35
-3
spec/uploaders/legacy_artifact_uploader_spec.rb
spec/uploaders/legacy_artifact_uploader_spec.rb
+20
-2
No files found.
app/uploaders/job_artifact_uploader.rb
View file @
38c61ab6
class
JobArtifactUploader
<
GitlabUploader
storage
:file
def
self
.
local_
artifacts_store
def
self
.
local_
store_path
Gitlab
.
config
.
artifacts
.
path
end
def
self
.
artifacts_upload_path
File
.
join
(
self
.
local_
artifacts_store
,
'tmp/uploads/'
)
File
.
join
(
self
.
local_
store_path
,
'tmp/uploads/'
)
end
def
size
...
...
@@ -15,8 +15,24 @@ class JobArtifactUploader < GitlabUploader
model
.
size
end
def
store_dir
default_local_path
end
def
cache_dir
File
.
join
(
self
.
class
.
local_store_path
,
'tmp/cache'
)
end
def
work_dir
File
.
join
(
self
.
class
.
local_store_path
,
'tmp/work'
)
end
private
def
default_local_path
File
.
join
(
self
.
class
.
local_store_path
,
default_path
)
end
def
default_path
creation_date
=
model
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
...
...
app/uploaders/legacy_artifact_uploader.rb
View file @
38c61ab6
...
...
@@ -6,7 +6,7 @@ class LegacyArtifactUploader < GitlabUploader
end
def
self
.
artifacts_upload_path
File
.
join
(
self
.
local_
artifacts_store
,
'tmp/uploads/'
)
File
.
join
(
self
.
local_
store_path
,
'tmp/uploads/'
)
end
def
store_dir
...
...
spec/factories/ci/builds.rb
View file @
38c61ab6
...
...
@@ -167,8 +167,8 @@ FactoryGirl.define do
trait
:artifacts
do
after
(
:create
)
do
|
build
|
create
(
:ci_job_artifact
,
job:
build
)
create
(
:ci_job_metadata
,
job:
build
)
create
(
:ci_job_artifact
,
:archive
,
job:
build
)
create
(
:ci_job_
artifact
,
:
metadata
,
job:
build
)
build
.
reload
end
end
...
...
spec/factories/ci/job_artifacts.rb
View file @
38c61ab6
...
...
@@ -9,22 +9,24 @@ FactoryGirl.define do
artifact
.
project
||=
artifact
.
job
.
project
end
after
:create
do
|
artifact
|
if
artifact
.
archive?
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
'application/zip'
)
artifact
.
save
trait
:archive
do
after
(
:create
)
do
|
artifact
,
_
|
artifact
.
update!
(
file_type: :archive
,
file:
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
'application/zip'
)
)
end
end
end
factory
:ci_job_metadata
,
parent: :ci_job_artifact
do
file_type
:metadata
after
:create
do
|
artifact
|
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts_metadata.gz'
),
'application/x-gzip'
)
artifact
.
save
trait
:metadata
do
after
(
:create
)
do
|
artifact
,
_
|
artifact
.
update!
(
file_type: :metadata
,
file:
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts_metadata.gz'
),
'application/x-gzip'
)
)
end
end
end
end
spec/migrations/migrate_old_artifacts_spec.rb
View file @
38c61ab6
...
...
@@ -40,7 +40,7 @@ describe MigrateOldArtifacts do
end
it
"legacy artifacts are set"
do
expect
(
build_with_legacy_artifacts
.
artifacts_file_identifier
).
not_to
be_nil
expect
(
build_with_legacy_artifacts
.
legacy_
artifacts_file_identifier
).
not_to
be_nil
end
describe
'#min_id'
do
...
...
spec/models/ci/job_artifact_spec.rb
View file @
38c61ab6
require
'spec_helper'
describe
Ci
::
JobArtifact
do
set
(
:artifact
)
{
create
(
:ci_job_artifact
)
}
set
(
:artifact
)
{
create
(
:ci_job_artifact
,
:archive
)
}
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
...
...
spec/models/project_statistics_spec.rb
View file @
38c61ab6
...
...
@@ -137,7 +137,7 @@ describe ProjectStatistics do
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_size:
56
.
megabytes
)
create
(
:ci_job_artifact
,
project:
pipeline
.
project
,
job:
ci_build
)
create
(
:ci_job_artifact
,
:archive
,
project:
pipeline
.
project
,
job:
ci_build
)
statistics
.
update_build_artifacts_size
end
...
...
spec/uploaders/job_artifact_uploader_spec.rb
View file @
38c61ab6
...
...
@@ -2,14 +2,46 @@ require 'spec_helper'
describe
JobArtifactUploader
do
set
(
:job_artifact
)
{
create
(
:ci_job_artifact
)
}
let
(
:job
)
{
job_artifact
.
job
}
let
(
:uploader
)
{
described_class
.
new
(
job_artifact
,
:file
)
}
let
(
:path
)
{
Gitlab
.
config
.
artifacts
.
path
}
describe
'#store_dir'
do
subject
{
uploader
.
store_dir
}
it
{
is_expected
.
to
start_with
(
Gitlab
.
config
.
artifacts
.
path
)
}
it
{
is_expected
.
not_to
end_with
(
"
#{
job
.
project_id
}
/
#{
job
.
created_at
.
utc
.
strftime
(
'%Y_%m'
)
}
/
#{
job
.
id
}
"
)
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
not_to
end_with
(
"
#{
job
_artifact
.
project_id
}
/
#{
job_artifact
.
created_at
.
utc
.
strftime
(
'%Y_%m'
)
}
/
#{
job_artifact
.
id
}
"
)
}
it
{
is_expected
.
to
match
(
/\h{2}\/\h{2}\/\h{64}\/\d{4}_\d{1,2}_\d{1,2}\/\d+\/\d+\z/
)
}
end
describe
'#cache_dir'
do
subject
{
uploader
.
cache_dir
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
end_with
(
'/tmp/cache'
)
}
end
describe
'#work_dir'
do
subject
{
uploader
.
work_dir
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
end_with
(
'/tmp/work'
)
}
end
context
'file is stored in valid path'
do
let
(
:file
)
do
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
'application/zip'
)
end
before
do
uploader
.
store!
(
file
)
end
subject
{
uploader
.
file
.
path
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
include
(
"/
#{
job_artifact
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
}
/"
)
}
it
{
is_expected
.
to
include
(
"/
#{
job_artifact
.
project_id
.
to_s
}
/"
)
}
it
{
is_expected
.
to
end_with
(
"ci_build_artifacts.zip"
)
}
end
end
spec/uploaders/legacy_artifact_uploader_spec.rb
View file @
38c61ab6
...
...
@@ -5,8 +5,8 @@ describe LegacyArtifactUploader do
let
(
:uploader
)
{
described_class
.
new
(
job
,
:artifacts_file
)
}
let
(
:path
)
{
Gitlab
.
config
.
artifacts
.
path
}
describe
'.local_
artifacts_store
'
do
subject
{
described_class
.
local_
artifacts_store
}
describe
'.local_
store_path
'
do
subject
{
described_class
.
local_
store_path
}
it
"delegate to artifacts path"
do
expect
(
Gitlab
.
config
.
artifacts
).
to
receive
(
:path
)
...
...
@@ -58,4 +58,22 @@ describe LegacyArtifactUploader do
it
{
is_expected
.
not_to
be_nil
}
end
end
context
'file is stored in valid path'
do
let
(
:file
)
do
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
'application/zip'
)
end
before
do
uploader
.
store!
(
file
)
end
subject
{
uploader
.
file
.
path
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
include
(
"/
#{
job
.
created_at
.
utc
.
strftime
(
'%Y_%m'
)
}
/"
)
}
it
{
is_expected
.
to
include
(
"/
#{
job
.
project_id
.
to_s
}
/"
)
}
it
{
is_expected
.
to
end_with
(
"ci_build_artifacts.zip"
)
}
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