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
0e51842d
Commit
0e51842d
authored
Mar 22, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move policy related specs our of YAML processor tests
parent
c7809d09
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
534 additions
and
580 deletions
+534
-580
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+3
-3
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+8
-2
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+2
-0
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+242
-0
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+18
-2
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+65
-482
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+196
-91
No files found.
lib/gitlab/ci/pipeline/seed/build.rb
View file @
0e51842d
...
...
@@ -15,8 +15,6 @@ module Gitlab
@except
=
attributes
.
delete
(
:except
)
end
# TODO find a different solution
#
def
user
=
(
current_user
)
@attributes
.
merge!
(
user:
current_user
)
end
...
...
@@ -43,10 +41,12 @@ module Gitlab
end
def
to_resource
strong_memoize
(
:resource
)
do
::
Ci
::
Build
.
new
(
attributes
)
end
end
end
end
end
end
end
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
0e51842d
...
...
@@ -3,7 +3,7 @@ module Gitlab
module
Pipeline
module
Seed
class
Stage
<
Seed
::
Base
attr_reader
:pipeline
,
:seeds
include
Gitlab
::
Utils
::
StrongMemoize
delegate
:size
,
to: :seeds
delegate
:dig
,
to: :seeds
...
...
@@ -27,10 +27,16 @@ module Gitlab
project:
@pipeline
.
project
}
end
def
seeds
strong_memoize
(
:seeds_included
)
do
@seeds
.
select
(
&
:included?
)
end
end
# TODO specs
#
def
included?
@seeds
.
any?
(
&
:included?
)
seeds
.
any?
end
def
to_resource
...
...
spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
View file @
0e51842d
...
...
@@ -129,4 +129,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect
{
step
.
perform!
}.
to
raise_error
(
described_class
::
PopulateError
)
end
end
pending
'populating pipeline according to policies'
end
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
0 → 100644
View file @
0e51842d
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:attributes
)
do
{
name:
'rspec'
,
ref:
'master'
,
commands:
'rspec'
}
end
subject
do
described_class
.
new
(
pipeline
,
attributes
)
end
describe
'#attributes'
do
it
'returns hash attributes of a build'
do
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
)
.
to
include
(
:name
,
:project
,
:ref
,
:commands
)
end
end
describe
'#user='
do
let
(
:user
)
{
build
(
:user
)
}
it
'assignes user to a build'
do
subject
.
user
=
user
expect
(
subject
.
attributes
).
to
include
(
user:
user
)
end
end
describe
'#to_resource'
do
it
'returns a valid build resource'
do
expect
(
subject
.
to_resource
).
to
be_a
(
::
Ci
::
Build
)
expect
(
subject
.
to_resource
).
to
be_valid
end
it
'memoizes a resource object'
do
build
=
subject
.
to_resource
expect
(
build
.
object_id
).
to
eq
subject
.
to_resource
.
object_id
end
it
'can not be persisted without explicit assignment'
do
build
=
subject
.
to_resource
pipeline
.
save!
expect
(
build
).
not_to
be_persisted
end
end
describe
'applying only/except policies'
do
context
'when no branch policy is specified'
do
let
(
:attributes
)
{
{
name:
'rspec'
}
}
it
{
is_expected
.
to
be_included
}
end
context
'when branch policy does not match'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'deploy'
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'deploy'
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
end
context
'when branch regexp policy does not match'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'/^deploy$/'
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'/^deploy$/'
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
end
context
'when branch policy matches'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'deploy'
,
'master'
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'deploy'
,
'master'
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
end
context
'when keyword policy matches'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'branches'
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'branches'
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
end
context
'when keyword policy does not match'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'tags'
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'tags'
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
end
context
'when keywords and pipeline source policy matches'
do
possibilities
=
[[
'pushes'
,
'push'
],
[
'web'
,
'web'
],
[
'triggers'
,
'trigger'
],
[
'schedules'
,
'schedule'
],
[
'api'
,
'api'
],
[
'external'
,
'external'
]]
context
'when using only'
do
possibilities
.
each
do
|
keyword
,
source
|
context
"when using keyword `
#{
keyword
}
` and source `
#{
source
}
`"
do
let
(
:pipeline
)
do
build
(
:ci_empty_pipeline
,
ref:
'deploy'
,
tag:
false
,
source:
source
)
end
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
keyword
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
end
end
context
'when using except'
do
possibilities
.
each
do
|
keyword
,
source
|
context
"when using keyword `
#{
keyword
}
` and source `
#{
source
}
`"
do
let
(
:pipeline
)
do
build
(
:ci_empty_pipeline
,
ref:
'deploy'
,
tag:
false
,
source:
source
)
end
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
keyword
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
end
end
end
context
'when keywords and pipeline source does not match'
do
possibilities
=
[[
'pushes'
,
'web'
],
[
'web'
,
'push'
],
[
'triggers'
,
'schedule'
],
[
'schedules'
,
'external'
],
[
'api'
,
'trigger'
],
[
'external'
,
'api'
]]
context
'when using only'
do
possibilities
.
each
do
|
keyword
,
source
|
context
"when using keyword `
#{
keyword
}
` and source `
#{
source
}
`"
do
let
(
:pipeline
)
do
build
(
:ci_empty_pipeline
,
ref:
'deploy'
,
tag:
false
,
source:
source
)
end
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
keyword
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
end
end
end
context
'when using except'
do
possibilities
.
each
do
|
keyword
,
source
|
context
"when using keyword `
#{
keyword
}
` and source `
#{
source
}
`"
do
let
(
:pipeline
)
do
build
(
:ci_empty_pipeline
,
ref:
'deploy'
,
tag:
false
,
source:
source
)
end
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
keyword
]
}
}
}
it
{
is_expected
.
to
be_included
}
end
end
end
end
context
'when repository path matches'
do
context
'when using only'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
only:
{
refs:
[
"branches@
#{
pipeline
.
project_full_path
}
"
]
}
}
end
it
{
is_expected
.
to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
except:
{
refs:
[
"branches@
#{
pipeline
.
project_full_path
}
"
]
}
}
end
it
{
is_expected
.
not_to
be_included
}
end
end
context
'when repository path does not matches'
do
context
'when using only'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
only:
{
refs:
[
'branches@fork'
]
}
}
end
it
{
is_expected
.
not_to
be_included
}
end
context
'when using except'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
except:
{
refs:
[
'branches@fork'
]
}
}
end
it
{
is_expected
.
to
be_included
}
end
end
end
end
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
0e51842d
...
...
@@ -6,7 +6,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
let
(
:attributes
)
do
{
name:
'test'
,
index:
0
,
builds:
[{
name:
'rspec'
},
{
name:
'spinach'
}]
}
builds:
[{
name:
'rspec'
},
{
name:
'spinach'
},
{
name:
'deploy'
,
only:
{
refs:
[
'feature'
]
}
}]
}
end
subject
do
...
...
@@ -27,7 +29,11 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
end
describe
'#seeds'
do
it
'returns hash attributes of all builds'
do
it
'returns build seeds'
do
expect
(
subject
.
seeds
).
to
all
(
be_a
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
)
end
it
'returns build seeds including valid attributes'
do
expect
(
subject
.
seeds
.
size
).
to
eq
2
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
tag:
false
))
...
...
@@ -55,6 +61,16 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
all
(
include
(
protected:
false
))
end
end
it
'filters seeds using only/except policies'
do
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
to
satisfy
do
|
seeds
|
seeds
.
any?
{
|
hash
|
hash
.
fetch
(
:name
)
==
'rspec'
}
end
expect
(
subject
.
seeds
.
map
(
&
:attributes
)).
not_to
satisfy
do
|
seeds
|
seeds
.
any?
{
|
hash
|
hash
.
fetch
(
:name
)
==
'deploy'
}
end
end
end
describe
'#user='
do
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
0e51842d
This diff is collapsed.
Click to expand it.
spec/models/ci/pipeline_spec.rb
View file @
0e51842d
...
...
@@ -215,6 +215,122 @@ describe Ci::Pipeline, :mailer do
end
describe
'pipeline stages'
do
describe
'#stage_seeds'
do
let
(
:pipeline
)
{
build
(
:ci_pipeline
,
config:
config
)
}
let
(
:config
)
{
{
rspec:
{
script:
'rake'
}
}
}
it
'returns preseeded stage seeds object'
do
expect
(
pipeline
.
stage_seeds
)
.
to
all
(
be_a
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Base
)
expect
(
pipeline
.
stage_seeds
.
count
).
to
eq
1
end
context
'when no refs policy is specified'
do
let
(
:config
)
do
{
production:
{
stage:
'deploy'
,
script:
'cap prod'
},
rspec:
{
stage:
'test'
,
script:
'rspec'
},
spinach:
{
stage:
'test'
,
script:
'spinach'
}
}
end
it
'correctly fabricates a stage seeds object'
do
seeds
=
pipeline
.
stage_seeds
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
dig
(
0
,
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
context
'when refs policy is specified'
do
let
(
:pipeline
)
do
build
(
:ci_pipeline
,
ref:
'feature'
,
tag:
true
,
config:
config
)
end
let
(
:config
)
do
{
production:
{
stage:
'deploy'
,
script:
'cap prod'
,
only:
[
'master'
]
},
spinach:
{
stage:
'test'
,
script:
'spinach'
,
only:
[
'tags'
]
}
}
end
it
'returns stage seeds only assigned to master to master'
do
seeds
=
pipeline
.
stage_seeds
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
context
'when source policy is specified'
do
let
(
:pipeline
)
{
build
(
:ci_pipeline
,
source: :schedule
,
config:
config
)
}
let
(
:config
)
do
{
production:
{
stage:
'deploy'
,
script:
'cap prod'
,
only:
[
'triggers'
]
},
spinach:
{
stage:
'test'
,
script:
'spinach'
,
only:
[
'schedules'
]
}
}
end
it
'returns stage seeds only assigned to schedules'
do
seeds
=
pipeline
.
stage_seeds
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
context
'when kubernetes policy is specified'
do
let
(
:config
)
do
{
spinach:
{
stage:
'test'
,
script:
'spinach'
},
production:
{
stage:
'deploy'
,
script:
'cap'
,
only:
{
kubernetes:
'active'
}
}
}
end
context
'when kubernetes is active'
do
shared_examples
'same behavior between KubernetesService and Platform::Kubernetes'
do
it
'returns seeds for kubernetes dependent job'
do
seeds
=
pipeline
.
stage_seeds
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
let
(
:pipeline
)
{
build
(
:ci_pipeline
,
project:
project
,
config:
config
)
}
it_behaves_like
'same behavior between KubernetesService and Platform::Kubernetes'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
let
(
:pipeline
)
{
build
(
:ci_pipeline
,
project:
project
,
config:
config
)
}
it_behaves_like
'same behavior between KubernetesService and Platform::Kubernetes'
end
end
context
'when kubernetes is not active'
do
it
'does not return seeds for kubernetes dependent job'
do
seeds
=
pipeline
.
stage_seeds
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
describe
'legacy stages'
do
before
do
create
(
:commit_status
,
pipeline:
pipeline
,
stage:
'build'
,
...
...
@@ -241,18 +357,6 @@ describe Ci::Pipeline, :mailer do
status:
'success'
)
end
describe
'#stage_seeds'
do
let
(
:pipeline
)
do
build
(
:ci_pipeline
,
config:
{
rspec:
{
script:
'rake'
}
})
end
it
'returns preseeded stage seeds object'
do
expect
(
pipeline
.
stage_seeds
)
.
to
all
(
be_a
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Base
)
expect
(
pipeline
.
stage_seeds
.
count
).
to
eq
1
end
end
describe
'#legacy_stages'
do
subject
{
pipeline
.
legacy_stages
}
...
...
@@ -347,6 +451,7 @@ describe Ci::Pipeline, :mailer do
end
end
end
end
describe
'state machine'
do
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
...
...
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