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
6a8133b9
Commit
6a8133b9
authored
Sep 07, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stub http request on specs intead of mocking HTTParty
CE mirror of bb2a9fde8e6a4d1df13638fe336f641b9c72ef59
parent
3af363ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
24 deletions
+32
-24
lib/gitlab/ci/external/file/remote.rb
lib/gitlab/ci/external/file/remote.rb
+8
-5
spec/lib/gitlab/ci/config_spec.rb
spec/lib/gitlab/ci/config_spec.rb
+9
-7
spec/lib/gitlab/ci/external/processor_spec.rb
spec/lib/gitlab/ci/external/processor_spec.rb
+9
-8
spec/models/blob_viewer/gitlab_ci_yml_spec.rb
spec/models/blob_viewer/gitlab_ci_yml_spec.rb
+6
-4
No files found.
lib/gitlab/ci/external/file/remote.rb
View file @
6a8133b9
...
...
@@ -3,6 +3,7 @@ module Gitlab
module
External
module
File
class
Remote
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:location
def
initialize
(
location
,
opts
=
{})
...
...
@@ -16,11 +17,13 @@ module Gitlab
def
content
return
@content
if
defined?
(
@content
)
@content
||=
begin
HTTParty
.
get
(
location
)
rescue
HTTParty
::
Error
,
Timeout
::
Error
false
end
@content
=
strong_memoize
(
:content
)
do
begin
HTTParty
.
get
(
location
)
rescue
HTTParty
::
Error
,
Timeout
::
Error
false
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config_spec.rb
View file @
6a8133b9
...
...
@@ -127,7 +127,7 @@ describe Gitlab::Ci::Config do
end
context
"when gitlab_ci_yml has valid 'include' defined"
do
let
(
:
http
_file_content
)
do
let
(
:
remote
_file_content
)
do
<<~
HEREDOC
variables:
AUTO_DEVOPS_DOMAIN: domain.example.com
...
...
@@ -138,11 +138,12 @@ describe Gitlab::Ci::Config do
HEREDOC
end
let
(
:local_file_content
)
{
File
.
read
(
"
#{
Rails
.
root
}
/spec/ee/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml"
)
}
let
(
:yml
)
do
let
(
:remote_location
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:gitlab_ci_yml
)
do
<<-
EOS
include:
- /spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml
-
https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml
-
#{
remote_location
}
image: ruby:2.2
EOS
...
...
@@ -150,7 +151,7 @@ describe Gitlab::Ci::Config do
before
do
allow_any_instance_of
(
::
Gitlab
::
Ci
::
External
::
File
::
Local
).
to
receive
(
:local_file_content
).
and_return
(
local_file_content
)
allow
(
HTTParty
).
to
receive
(
:get
).
and_return
(
http
_file_content
)
WebMock
.
stub_request
(
:get
,
remote_location
).
to_return
(
body:
remote
_file_content
)
end
it
'should return a composed hash'
do
...
...
@@ -194,23 +195,24 @@ describe Gitlab::Ci::Config do
end
context
"when both external files and gitlab_ci.yml defined the same key"
do
let
(
:remote_location
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:gitlab_ci_yml
)
do
<<~
HEREDOC
include:
-
https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.gitlab_ci_yml
-
#{
remote_location
}
image: ruby:2.2
HEREDOC
end
let
(
:
http
_file_content
)
do
let
(
:
remote
_file_content
)
do
<<~
HEREDOC
image: php:5-fpm-alpine
HEREDOC
end
it
'should take precedence'
do
allow
(
HTTParty
).
to
receive
(
:get
).
and_return
(
http
_file_content
)
WebMock
.
stub_request
(
:get
,
remote_location
).
to_return
(
body:
remote
_file_content
)
expect
(
config
.
to_hash
).
to
eq
({
image:
'ruby:2.2'
})
end
end
...
...
spec/lib/gitlab/ci/external/processor_spec.rb
View file @
6a8133b9
...
...
@@ -36,8 +36,8 @@ describe Gitlab::Ci::External::Processor do
end
context
'with a valid remote external file is defined'
do
let
(
:remote_
url
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:values
)
{
{
include:
remote_
url
,
image:
'ruby:2.2'
}
}
let
(
:remote_
file
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:values
)
{
{
include:
remote_
file
,
image:
'ruby:2.2'
}
}
let
(
:external_file_content
)
do
<<-
HEREDOC
before_script:
...
...
@@ -58,7 +58,7 @@ describe Gitlab::Ci::External::Processor do
end
before
do
WebMock
.
stub_request
(
:get
,
remote_
url
).
to_return
(
body:
external_file_content
)
WebMock
.
stub_request
(
:get
,
remote_
file
).
to_return
(
body:
external_file_content
)
end
it
'should append the file to the values'
do
...
...
@@ -99,11 +99,11 @@ describe Gitlab::Ci::External::Processor do
end
context
'with multiple external files are defined'
do
let
(
:remote_
url
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:remote_
file
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:external_files
)
do
[
"/spec/ee/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml"
,
remote_
url
remote_
file
]
end
let
(
:values
)
do
...
...
@@ -125,7 +125,7 @@ describe Gitlab::Ci::External::Processor do
before
do
local_file_content
=
File
.
read
(
"
#{
Rails
.
root
}
/spec/ee/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml"
)
allow_any_instance_of
(
Gitlab
::
Ci
::
External
::
File
::
Local
).
to
receive
(
:local_file_content
).
and_return
(
local_file_content
)
WebMock
.
stub_request
(
:get
,
remote_
url
).
to_return
(
body:
remote_file_content
)
WebMock
.
stub_request
(
:get
,
remote_
file
).
to_return
(
body:
remote_file_content
)
end
it
'should append the files to the values'
do
...
...
@@ -152,9 +152,10 @@ describe Gitlab::Ci::External::Processor do
end
context
"when both external files and values defined the same key"
do
let
(
:remote_file
)
{
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
}
let
(
:values
)
do
{
include:
'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml'
,
include:
remote_file
,
image:
'ruby:2.2'
}
end
...
...
@@ -166,7 +167,7 @@ describe Gitlab::Ci::External::Processor do
end
it
'should take precedence'
do
allow
(
HTTParty
).
to
receive
(
:get
).
and_return
(
remote_file_content
)
WebMock
.
stub_request
(
:get
,
remote_file
).
to_return
(
body:
remote_file_content
)
expect
(
processor
.
perform
[
:image
]).
to
eq
(
'ruby:2.2'
)
end
end
...
...
spec/models/blob_viewer/gitlab_ci_yml_spec.rb
View file @
6a8133b9
...
...
@@ -2,22 +2,24 @@ require 'spec_helper'
describe
BlobViewer
::
GitlabCiYml
do
include
FakeBlobHelpers
include
RepoHelpers
let
(
:project
)
{
build_stubbed
(
:project
)
}
let
(
:project
)
{
build_stubbed
(
:project
,
:repository
)
}
let
(
:data
)
{
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
}
let
(
:blob
)
{
fake_blob
(
path:
'.gitlab-ci.yml'
,
data:
data
)
}
let
(
:sha
)
{
sample_commit
.
id
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#validation_message'
do
it
'calls prepare! on the viewer'
do
expect
(
subject
).
to
receive
(
:prepare!
)
subject
.
validation_message
(
project
,
project
.
default_branch
)
subject
.
validation_message
(
project
,
sha
)
end
context
'when the configuration is valid'
do
it
'returns nil'
do
expect
(
subject
.
validation_message
(
project
,
project
.
default_branch
)).
to
be_nil
expect
(
subject
.
validation_message
(
project
,
sha
)).
to
be_nil
end
end
...
...
@@ -25,7 +27,7 @@ describe BlobViewer::GitlabCiYml do
let
(
:data
)
{
'oof'
}
it
'returns the error message'
do
expect
(
subject
.
validation_message
(
project
,
project
.
default_branch
)).
to
eq
(
'Invalid configuration format'
)
expect
(
subject
.
validation_message
(
project
,
sha
)).
to
eq
(
'Invalid configuration format'
)
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