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
565fdd63
Commit
565fdd63
authored
Feb 12, 2018
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rearrange the test structure and introduce
a new repository location class.
parent
2f34ef34
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
51 deletions
+103
-51
qa/qa/git/repository.rb
qa/qa/git/repository.rb
+2
-13
qa/qa/git/repository/location.rb
qa/qa/git/repository/location.rb
+41
-0
qa/qa/page/project/show.rb
qa/qa/page/project/show.rb
+4
-0
qa/qa/specs/features/project/deploy_key_clone_spec.rb
qa/qa/specs/features/project/deploy_key_clone_spec.rb
+47
-32
qa/spec/git/repository/location_spec.rb
qa/spec/git/repository/location_spec.rb
+9
-6
No files found.
qa/qa/git/repository.rb
View file @
565fdd63
...
...
@@ -4,20 +4,9 @@ require 'uri'
module
QA
module
Git
class
Repository
include
Scenario
::
Actable
autoload
:Location
,
'qa/git/repository/location'
# See: config/initializers/1_settings.rb
# Settings#build_gitlab_shell_ssh_path_prefix
def
self
.
parse_uri
(
git_uri
)
if
git_uri
.
start_with?
(
'ssh://'
)
URI
.
parse
(
git_uri
)
else
*
rest
,
path
=
git_uri
.
split
(
':'
)
# Host cannot have : so we'll need to escape it
user_host
=
rest
.
join
(
'%3A'
).
sub
(
/\A\[(.+)\]\z/
,
'\1'
)
URI
.
parse
(
"ssh://
#{
user_host
}
/
#{
path
}
"
)
end
end
include
Scenario
::
Actable
def
self
.
perform
(
*
args
)
Dir
.
mktmpdir
do
|
dir
|
...
...
qa/qa/git/repository/location.rb
0 → 100644
View file @
565fdd63
require
'uri'
require
'forwardable'
module
QA
module
Git
class
Repository
class
Location
extend
Forwardable
attr_reader
:git_uri
,
:uri
def_delegators
:@uri
,
:user
,
:host
,
:path
# See: config/initializers/1_settings.rb
# Settings#build_gitlab_shell_ssh_path_prefix
def
self
.
parse
(
git_uri
)
if
git_uri
.
start_with?
(
'ssh://'
)
new
(
git_uri
,
URI
.
parse
(
git_uri
))
else
*
rest
,
path
=
git_uri
.
split
(
':'
)
# Host cannot have : so we'll need to escape it
user_host
=
rest
.
join
(
'%3A'
).
sub
(
/\A\[(.+)\]\z/
,
'\1'
)
new
(
git_uri
,
URI
.
parse
(
"ssh://
#{
user_host
}
/
#{
path
}
"
))
end
end
def
initialize
(
git_uri
,
uri
)
@git_uri
=
git_uri
@uri
=
uri
end
def
scheme
uri
.
scheme
||
'ssh'
end
def
port
uri
.
port
||
22
end
end
end
end
end
qa/qa/page/project/show.rb
View file @
565fdd63
...
...
@@ -33,6 +33,10 @@ module QA
find
(
'#project_clone'
).
value
end
def
repository_location_uri
Git
::
Repository
::
Location
.
parse
(
repository_location
)
end
def
project_name
find
(
'.qa-project-name'
).
text
end
...
...
qa/qa/specs/features/project/deploy_key_clone_spec.rb
View file @
565fdd63
...
...
@@ -3,72 +3,87 @@ require 'digest/sha1'
module
QA
feature
'cloning code using a deploy key'
,
:core
,
:docker
do
let
(
:runner_name
)
{
"qa-runner-
#{
Time
.
now
.
to_i
}
"
}
let
(
:key
)
{
Runtime
::
RSAKey
.
new
}
after
do
Service
::
Runner
.
new
(
runner_name
).
remove!
end
scenario
'user sets up a deploy key to clone code using pipelines'
do
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Page
::
Main
::
Login
.
act
{
sign_in_using_credentials
}
project
=
Factory
::
Resource
::
Project
.
fabricate!
do
|
resource
|
given
(
:project
)
do
Factory
::
Resource
::
Project
.
fabricate!
do
|
resource
|
resource
.
name
=
'deploy-key-clone-project'
end
Factory
::
Resource
::
Runner
.
fabricate!
do
|
runner
|
runner
.
project
=
project
runner
.
name
=
runner_name
runner
.
tags
=
%w[qa docker]
runner
.
image
=
'gitlab/gitlab-runner:ubuntu'
end
key
=
Runtime
::
RSAKey
.
new
def
fabricate_runner
Factory
::
Resource
::
Runner
.
fabricate!
do
|
resource
|
resource
.
project
=
project
resource
.
name
=
runner_name
resource
.
tags
=
%w[qa docker]
resource
.
image
=
'gitlab/gitlab-runner:ubuntu'
end
end
def
fabricate_deploy_key
Factory
::
Resource
::
DeployKey
.
fabricate!
do
|
resource
|
resource
.
project
=
project
resource
.
title
=
'deploy key title'
resource
.
key
=
key
.
public_key
end
end
def
fabricate_secret_variable
Factory
::
Resource
::
SecretVariable
.
fabricate!
do
|
resource
|
resource
.
project
=
project
resource
.
key
=
'DEPLOY_KEY'
resource
.
value
=
key
.
to_pem
end
end
project
.
visit!
repository_url
=
Page
::
Project
::
Show
.
act
do
def
fabricate_gitlab_ci
repository_uri
=
Page
::
Project
::
Show
.
act
do
choose_repository_clone_ssh
repository_location
repository_location
_uri
end
repository_uri
=
Git
::
Repository
.
parse_uri
(
repository_url
)
gitlab_ci
=
<<~
YAML
<<~
YAML
cat-config:
script:
- mkdir -p ~/.ssh
- ssh-keyscan -p
#{
repository_uri
.
port
||
22
}
#{
repository_uri
.
host
}
>> ~/.ssh/known_hosts
- ssh-keyscan -p
#{
repository_uri
.
port
}
#{
repository_uri
.
host
}
>> ~/.ssh/known_hosts
- eval $(ssh-agent -s)
- echo "$DEPLOY_KEY" | ssh-add -
- git clone
#{
repository_ur
l
}
- git clone
#{
repository_ur
i
.
git_uri
}
- sha1sum
#{
project
.
name
}
/.gitlab-ci.yml
tags:
- qa
- docker
YAML
end
sha1sum
=
Digest
::
SHA1
.
hexdigest
(
gitlab_ci
)
def
fabricate_push
(
gitlab_ci
)
Factory
::
Repository
::
Push
.
fabricate!
do
|
resource
|
resource
.
project
=
project
resource
.
file_name
=
'.gitlab-ci.yml'
resource
.
commit_message
=
'Add .gitlab-ci.yml'
resource
.
file_content
=
gitlab_ci
end
end
Factory
::
Repository
::
Push
.
fabricate!
do
|
push
|
push
.
project
=
project
push
.
file_name
=
'.gitlab-ci.yml'
push
.
commit_message
=
'Add .gitlab-ci.yml'
push
.
file_content
=
gitlab_ci
after
do
Service
::
Runner
.
new
(
runner_name
).
remove!
end
scenario
'user sets up a deploy key to clone code using pipelines'
do
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Page
::
Main
::
Login
.
act
{
sign_in_using_credentials
}
fabricate_runner
fabricate_deploy_key
fabricate_secret_variable
project
.
visit!
gitlab_ci
=
fabricate_gitlab_ci
fabricate_push
(
gitlab_ci
)
sha1sum
=
Digest
::
SHA1
.
hexdigest
(
gitlab_ci
)
Page
::
Project
::
Show
.
act
{
wait_for_push
}
Page
::
Menu
::
Side
.
act
{
click_ci_cd_pipelines
}
Page
::
Project
::
Pipeline
::
Index
.
act
{
go_to_latest_pipeline
}
...
...
qa/spec/git/repository_spec.rb
→
qa/spec/git/repository
/location
_spec.rb
View file @
565fdd63
describe
QA
::
Git
::
Repository
do
describe
'.parse
_uri
'
do
describe
QA
::
Git
::
Repository
::
Location
do
describe
'.parse'
do
context
'when URI starts with ssh://'
do
context
'when URI has port'
do
it
'parses correctly'
do
uri
=
described_class
.
parse
_uri
(
'ssh://git@qa.test:2222/sandbox/qa/repo.git'
)
.
parse
(
'ssh://git@qa.test:2222/sandbox/qa/repo.git'
)
expect
(
uri
.
user
).
to
eq
(
'git'
)
expect
(
uri
.
host
).
to
eq
(
'qa.test'
)
...
...
@@ -16,10 +16,11 @@ describe QA::Git::Repository do
context
'when URI does not have port'
do
it
'parses correctly'
do
uri
=
described_class
.
parse
_uri
(
'ssh://git@qa.test/sandbox/qa/repo.git'
)
.
parse
(
'ssh://git@qa.test/sandbox/qa/repo.git'
)
expect
(
uri
.
user
).
to
eq
(
'git'
)
expect
(
uri
.
host
).
to
eq
(
'qa.test'
)
expect
(
uri
.
port
).
to
eq
(
22
)
expect
(
uri
.
path
).
to
eq
(
'/sandbox/qa/repo.git'
)
end
end
...
...
@@ -29,10 +30,11 @@ describe QA::Git::Repository do
context
'when host does not have colons'
do
it
'parses correctly'
do
uri
=
described_class
.
parse
_uri
(
'git@qa.test:sandbox/qa/repo.git'
)
.
parse
(
'git@qa.test:sandbox/qa/repo.git'
)
expect
(
uri
.
user
).
to
eq
(
'git'
)
expect
(
uri
.
host
).
to
eq
(
'qa.test'
)
expect
(
uri
.
port
).
to
eq
(
22
)
expect
(
uri
.
path
).
to
eq
(
'/sandbox/qa/repo.git'
)
end
end
...
...
@@ -40,10 +42,11 @@ describe QA::Git::Repository do
context
'when host has a colon'
do
it
'parses correctly'
do
uri
=
described_class
.
parse
_uri
(
'[git@qa:test]:sandbox/qa/repo.git'
)
.
parse
(
'[git@qa:test]:sandbox/qa/repo.git'
)
expect
(
uri
.
user
).
to
eq
(
'git'
)
expect
(
uri
.
host
).
to
eq
(
'qa%3Atest'
)
expect
(
uri
.
port
).
to
eq
(
22
)
expect
(
uri
.
path
).
to
eq
(
'/sandbox/qa/repo.git'
)
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