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
bf6126b1
Commit
bf6126b1
authored
Nov 27, 2017
by
Zeger-Jan van de Weg
Committed by
Kamil Trzcinski
Dec 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add coverage on legacy artifacts for Ci::Build
parent
e35f1607
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
190 additions
and
77 deletions
+190
-77
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+171
-70
spec/models/project_statistics_spec.rb
spec/models/project_statistics_spec.rb
+19
-7
No files found.
spec/models/ci/build_spec.rb
View file @
bf6126b1
...
@@ -132,27 +132,55 @@ describe Ci::Build do
...
@@ -132,27 +132,55 @@ describe Ci::Build do
end
end
describe
'#artifacts?'
do
describe
'#artifacts?'
do
let
(
:build
)
{
create
(
:ci_build
,
:artifacts
)
}
context
'when new artifacts are used'
do
let
(
:build
)
{
create
(
:ci_build
,
:artifacts
)
}
subject
{
build
.
artifacts?
}
subject
{
build
.
artifacts?
}
context
'artifacts archive does not exist'
do
context
'artifacts archive does not exist'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
it
{
is_expected
.
to
be_falsy
}
it
{
is_expected
.
to
be_falsy
}
end
context
'artifacts archive exists'
do
it
{
is_expected
.
to
be_truthy
}
context
'is expired'
do
let!
(
:build
)
{
create
(
:ci_build
,
:artifacts
,
:expired
)
}
it
{
is_expected
.
to
be_falsy
}
end
context
'is not expired'
do
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
context
'artifacts archive exists'
do
context
'when legacy artifacts are used'
do
it
{
is_expected
.
to
be_truthy
}
let
(
:build
)
{
create
(
:ci_build
,
:legacy_artifacts
)
}
subject
{
build
.
artifacts?
}
context
'
is expired
'
do
context
'
artifacts archive does not exist
'
do
let
!
(
:build
)
{
create
(
:ci_build
,
:artifacts
,
:expire
d
)
}
let
(
:build
)
{
create
(
:ci_buil
d
)
}
it
{
is_expected
.
to
be_falsy
}
it
{
is_expected
.
to
be_falsy
}
end
end
context
'
is not expired
'
do
context
'
artifacts archive exists
'
do
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
context
'is expired'
do
let!
(
:build
)
{
create
(
:ci_build
,
:legacy_artifacts
,
:expired
)
}
it
{
is_expected
.
to
be_falsy
}
end
context
'is not expired'
do
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
end
end
end
...
@@ -607,71 +635,144 @@ describe Ci::Build do
...
@@ -607,71 +635,144 @@ describe Ci::Build do
describe
'#erasable?'
do
describe
'#erasable?'
do
subject
{
build
.
erasable?
}
subject
{
build
.
erasable?
}
it
{
is_expected
.
to
eq
false
}
it
{
is_expected
.
to
eq
false
}
end
end
end
end
context
'build is erasable'
do
context
'build is erasable'
do
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:artifacts
)
}
context
'new artifacts'
do
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:artifacts
)
}
describe
'#erase'
do
describe
'#erase'
do
before
do
before
do
build
.
erase
(
erased_by:
user
)
build
.
erase
(
erased_by:
user
)
end
end
context
'erased by user'
do
context
'erased by user'
do
let!
(
:user
)
{
create
(
:user
,
username:
'eraser'
)
}
let!
(
:user
)
{
create
(
:user
,
username:
'eraser'
)
}
include_examples
'erasable'
include_examples
'erasable'
it
'records user who erased a build'
do
it
'records user who erased a build'
do
expect
(
build
.
erased_by
).
to
eq
user
expect
(
build
.
erased_by
).
to
eq
user
end
end
end
end
context
'erased by system'
do
context
'erased by system'
do
let
(
:user
)
{
nil
}
let
(
:user
)
{
nil
}
include_examples
'erasable'
include_examples
'erasable'
it
'does not set user who erased a build'
do
it
'does not set user who erased a build'
do
expect
(
build
.
erased_by
).
to
be_nil
expect
(
build
.
erased_by
).
to
be_nil
end
end
end
end
end
end
describe
'#erasable?'
do
describe
'#erasable?'
do
subject
{
build
.
erasable?
}
subject
{
build
.
erasable?
}
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
end
end
describe
'#erased?'
do
describe
'#erased?'
do
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:artifacts
)
}
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:artifacts
)
}
subject
{
build
.
erased?
}
subject
{
build
.
erased?
}
context
'job has not been erased'
do
context
'job has not been erased'
do
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
context
'job has been erased'
do
before
do
build
.
erase
end
it
{
is_expected
.
to
be_truthy
}
end
end
end
context
'job has been erased'
do
context
'metadata and build trace are not available'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:artifacts
)
}
before
do
before
do
build
.
erase
build
.
remove_artifacts_metadata!
end
end
it
{
is_expected
.
to
be_truthy
}
describe
'#erase'
do
it
'does not raise error'
do
expect
{
build
.
erase
}.
not_to
raise_error
end
end
end
end
end
end
end
context
'metadata and build trace are not available'
do
context
'old artifacts'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:artifacts
)
}
context
'build is erasable'
do
context
'new artifacts'
do
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:legacy_artifacts
)
}
before
do
describe
'#erase'
do
build
.
remove_artifacts_metadata!
before
do
end
build
.
erase
(
erased_by:
user
)
end
describe
'#erase'
do
context
'erased by user'
do
it
'does not raise error'
do
let!
(
:user
)
{
create
(
:user
,
username:
'eraser'
)
}
expect
{
build
.
erase
}.
not_to
raise_error
include_examples
'erasable'
it
'records user who erased a build'
do
expect
(
build
.
erased_by
).
to
eq
user
end
end
context
'erased by system'
do
let
(
:user
)
{
nil
}
include_examples
'erasable'
it
'does not set user who erased a build'
do
expect
(
build
.
erased_by
).
to
be_nil
end
end
end
describe
'#erasable?'
do
subject
{
build
.
erasable?
}
it
{
is_expected
.
to
be_truthy
}
end
describe
'#erased?'
do
let!
(
:build
)
{
create
(
:ci_build
,
:trace
,
:success
,
:legacy_artifacts
)
}
subject
{
build
.
erased?
}
context
'job has not been erased'
do
it
{
is_expected
.
to
be_falsey
}
end
context
'job has been erased'
do
before
do
build
.
erase
end
it
{
is_expected
.
to
be_truthy
}
end
end
context
'metadata and build trace are not available'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:legacy_artifacts
)
}
before
do
build
.
remove_artifacts_metadata!
end
describe
'#erase'
do
it
'does not raise error'
do
expect
{
build
.
erase
}.
not_to
raise_error
end
end
end
end
end
end
end
end
...
@@ -917,9 +1018,9 @@ describe Ci::Build do
...
@@ -917,9 +1018,9 @@ describe Ci::Build do
describe
'#merge_request'
do
describe
'#merge_request'
do
def
create_mr
(
build
,
pipeline
,
factory: :merge_request
,
created_at:
Time
.
now
)
def
create_mr
(
build
,
pipeline
,
factory: :merge_request
,
created_at:
Time
.
now
)
create
(
factory
,
source_project:
pipeline
.
project
,
create
(
factory
,
source_project:
pipeline
.
project
,
target_project:
pipeline
.
project
,
target_project:
pipeline
.
project
,
source_branch:
build
.
ref
,
source_branch:
build
.
ref
,
created_at:
created_at
)
created_at:
created_at
)
end
end
context
'when a MR has a reference to the pipeline'
do
context
'when a MR has a reference to the pipeline'
do
...
@@ -1218,7 +1319,7 @@ describe Ci::Build do
...
@@ -1218,7 +1319,7 @@ describe Ci::Build do
context
'when `when` is undefined'
do
context
'when `when` is undefined'
do
before
do
before
do
build
.
when
=
nil
build
.
when
=
nil
end
end
context
'use from gitlab-ci.yml'
do
context
'use from gitlab-ci.yml'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
...
@@ -1236,10 +1337,10 @@ describe Ci::Build do
...
@@ -1236,10 +1337,10 @@ describe Ci::Build do
context
'when config does not have a questioned job'
do
context
'when config does not have a questioned job'
do
let
(
:config
)
do
let
(
:config
)
do
YAML
.
dump
({
YAML
.
dump
({
test_other:
{
test_other:
{
script:
'Hello World'
script:
'Hello World'
}
}
})
})
end
end
it
{
is_expected
.
to
eq
(
'on_success'
)
}
it
{
is_expected
.
to
eq
(
'on_success'
)
}
...
@@ -1248,18 +1349,18 @@ describe Ci::Build do
...
@@ -1248,18 +1349,18 @@ describe Ci::Build do
context
'when config has `when`'
do
context
'when config has `when`'
do
let
(
:config
)
do
let
(
:config
)
do
YAML
.
dump
({
YAML
.
dump
({
test:
{
test:
{
script:
'Hello World'
,
script:
'Hello World'
,
when:
'always'
when:
'always'
}
}
})
})
end
end
it
{
is_expected
.
to
eq
(
'always'
)
}
it
{
is_expected
.
to
eq
(
'always'
)
}
end
end
end
end
end
end
end
end
describe
'#variables'
do
describe
'#variables'
do
let
(
:container_registry_enabled
)
{
false
}
let
(
:container_registry_enabled
)
{
false
}
...
@@ -1333,10 +1434,10 @@ describe Ci::Build do
...
@@ -1333,10 +1434,10 @@ describe Ci::Build do
let!
(
:environment
)
do
let!
(
:environment
)
do
create
(
:environment
,
create
(
:environment
,
project:
build
.
project
,
project:
build
.
project
,
name:
'production'
,
name:
'production'
,
slug:
'prod-slug'
,
slug:
'prod-slug'
,
external_url:
''
)
external_url:
''
)
end
end
before
do
before
do
...
@@ -1362,7 +1463,7 @@ describe Ci::Build do
...
@@ -1362,7 +1463,7 @@ describe Ci::Build do
before
do
before
do
environment_variables
<<
environment_variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
url
,
public:
true
}
{
key:
'CI_ENVIRONMENT_URL'
,
value:
url
,
public:
true
}
end
end
context
'when the URL was set from the job'
do
context
'when the URL was set from the job'
do
...
@@ -1560,8 +1661,8 @@ describe Ci::Build do
...
@@ -1560,8 +1661,8 @@ describe Ci::Build do
let!
(
:pipeline_schedule_variable
)
do
let!
(
:pipeline_schedule_variable
)
do
create
(
:ci_pipeline_schedule_variable
,
create
(
:ci_pipeline_schedule_variable
,
key:
'SCHEDULE_VARIABLE_KEY'
,
key:
'SCHEDULE_VARIABLE_KEY'
,
pipeline_schedule:
pipeline_schedule
)
pipeline_schedule:
pipeline_schedule
)
end
end
before
do
before
do
...
@@ -1703,8 +1804,8 @@ describe Ci::Build do
...
@@ -1703,8 +1804,8 @@ describe Ci::Build do
allow_any_instance_of
(
Project
)
allow_any_instance_of
(
Project
)
.
to
receive
(
:secret_variables_for
)
.
to
receive
(
:secret_variables_for
)
.
with
(
ref:
'master'
,
environment:
nil
)
do
.
with
(
ref:
'master'
,
environment:
nil
)
do
[
create
(
:ci_variable
,
key:
'secret'
,
value:
'value'
)]
[
create
(
:ci_variable
,
key:
'secret'
,
value:
'value'
)]
end
end
allow_any_instance_of
(
Ci
::
Pipeline
)
allow_any_instance_of
(
Ci
::
Pipeline
)
.
to
receive
(
:predefined_variables
)
{
[
pipeline_pre_var
]
}
.
to
receive
(
:predefined_variables
)
{
[
pipeline_pre_var
]
}
...
...
spec/models/project_statistics_spec.rb
View file @
bf6126b1
...
@@ -133,17 +133,29 @@ describe ProjectStatistics do
...
@@ -133,17 +133,29 @@ describe ProjectStatistics do
describe
'#update_build_artifacts_size'
do
describe
'#update_build_artifacts_size'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let!
(
:ci_build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_size:
45
.
megabytes
)
}
before
do
context
'when new job artifacts are calculated'
do
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_size:
56
.
megabytes
)
let
(
:ci_build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
create
(
:ci_job_artifact
,
:archive
,
project:
pipeline
.
project
,
job:
ci_build
)
before
do
create
(
:ci_job_artifact
,
:archive
,
project:
pipeline
.
project
,
job:
ci_build
)
end
it
"stores the size of related build artifacts"
do
statistics
.
update_build_artifacts_size
statistics
.
update_build_artifacts_size
expect
(
statistics
.
build_artifacts_size
).
to
be
(
106365
)
end
end
end
it
"stores the size of related build artifacts"
do
context
'when legacy artifacts are used'
do
expect
(
statistics
.
build_artifacts_size
).
to
eq
(
106012541
)
let!
(
:ci_build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_size:
10
.
megabytes
)
}
it
"stores the size of related build artifacts"
do
statistics
.
update_build_artifacts_size
expect
(
statistics
.
build_artifacts_size
).
to
eq
(
10
.
megabytes
)
end
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