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
Léo-Paul Géneau
gitlab-ce
Commits
a644f4b8
Commit
a644f4b8
authored
Oct 04, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec/models/gcp/cluster_spec.rb
parent
ea4af856
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
411 additions
and
1 deletion
+411
-1
app/models/gcp/cluster.rb
app/models/gcp/cluster.rb
+1
-1
spec/factories/gcp/cluster.rb
spec/factories/gcp/cluster.rb
+23
-0
spec/models/gcp/cluster_spec.rb
spec/models/gcp/cluster_spec.rb
+266
-0
spec/services/ci/create_cluster_service_spec.rb
spec/services/ci/create_cluster_service_spec.rb
+19
-0
spec/services/ci/fetch_gcp_operation_service_spec.rb
spec/services/ci/fetch_gcp_operation_service_spec.rb
+17
-0
spec/services/ci/fetch_kubernetes_token_service_spec.rb
spec/services/ci/fetch_kubernetes_token_service_spec.rb
+17
-0
spec/services/ci/finalize_cluster_creation_service_spec.rb
spec/services/ci/finalize_cluster_creation_service_spec.rb
+17
-0
spec/services/ci/integrate_cluster_service_spec.rb
spec/services/ci/integrate_cluster_service_spec.rb
+17
-0
spec/services/ci/provision_cluster_service_spec.rb
spec/services/ci/provision_cluster_service_spec.rb
+17
-0
spec/services/ci/update_cluster_service_spec.rb
spec/services/ci/update_cluster_service_spec.rb
+17
-0
No files found.
app/models/gcp/cluster.rb
View file @
a644f4b8
...
@@ -84,7 +84,7 @@ module Gcp
...
@@ -84,7 +84,7 @@ module Gcp
cluster
.
gcp_operation_id
=
nil
cluster
.
gcp_operation_id
=
nil
end
end
before_transition
any
=>
[
:errored
]
do
|
cluster
|
before_transition
any
=>
[
:errored
]
do
|
cluster
,
transition
|
status_reason
=
transition
.
args
.
first
status_reason
=
transition
.
args
.
first
cluster
.
status_reason
=
status_reason
cluster
.
status_reason
=
status_reason
end
end
...
...
spec/factories/gcp/cluster.rb
0 → 100644
View file @
a644f4b8
FactoryGirl
.
define
do
factory
:gcp_cluster
,
class:
Gcp
::
Cluster
do
project
user
enabled
true
gcp_project_id
'gcp-project-12345'
gcp_cluster_name
'test-cluster'
gcp_cluster_zone
'us-central1-a'
gcp_cluster_size
1
trait
:with_kubernetes_service
do
service
:kubernetes_service
end
trait
:created_on_gke
do
endpoint
'111.111.111.111'
ca_cert
'xxxxxx'
kubernetes_token
'xxxxxx'
username
'xxxxxx'
password
'xxxxxx'
end
end
end
spec/models/gcp/cluster_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Gcp
::
Cluster
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:service
)
}
it
{
is_expected
.
to
validate_presence_of
(
:gcp_cluster_zone
)
}
describe
'#default_value_for'
do
let
(
:cluster
)
{
described_class
.
new
}
it
{
expect
(
cluster
.
gcp_cluster_zone
).
to
eq
(
'us-central1-a'
)
}
it
{
expect
(
cluster
.
gcp_cluster_size
).
to
eq
(
3
)
}
it
{
expect
(
cluster
.
gcp_machine_type
).
to
eq
(
'n1-standard-4'
)
}
end
describe
'#validates'
do
subject
{
cluster
.
valid?
}
context
'when validates gcp_project_id'
do
let
(
:cluster
)
{
build
(
:gcp_cluster
,
gcp_project_id:
gcp_project_id
)
}
context
'when valid'
do
let
(
:gcp_project_id
)
{
'gcp-project-12345'
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when empty'
do
let
(
:gcp_project_id
)
{
''
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when too long'
do
let
(
:gcp_project_id
)
{
'A'
*
64
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when includes abnormal character'
do
let
(
:gcp_project_id
)
{
'!!!!!!'
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when validates gcp_cluster_name'
do
let
(
:cluster
)
{
build
(
:gcp_cluster
,
gcp_cluster_name:
gcp_cluster_name
)
}
context
'when valid'
do
let
(
:gcp_cluster_name
)
{
'test-cluster'
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when empty'
do
let
(
:gcp_cluster_name
)
{
''
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when too long'
do
let
(
:gcp_cluster_name
)
{
'A'
*
64
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when includes abnormal character'
do
let
(
:gcp_cluster_name
)
{
'!!!!!!'
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when validates gcp_cluster_size'
do
let
(
:cluster
)
{
build
(
:gcp_cluster
,
gcp_cluster_size:
gcp_cluster_size
)
}
context
'when valid'
do
let
(
:gcp_cluster_size
)
{
1
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when zero'
do
let
(
:gcp_cluster_size
)
{
0
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when validates project_namespace'
do
let
(
:cluster
)
{
build
(
:gcp_cluster
,
project_namespace:
project_namespace
)
}
context
'when valid'
do
let
(
:project_namespace
)
{
'default-namespace'
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when empty'
do
let
(
:project_namespace
)
{
''
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when too long'
do
let
(
:project_namespace
)
{
'A'
*
64
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when includes abnormal character'
do
let
(
:project_namespace
)
{
'!!!!!!'
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when validates restrict_modification'
do
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
before
do
cluster
.
creating!
end
context
'when created'
do
before
do
cluster
.
created!
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when creating'
do
it
{
is_expected
.
to
be_falsey
}
end
end
end
describe
'#state_machine'
do
let
(
:cluster
)
{
build
(
:gcp_cluster
)
}
context
'when transits to created state'
do
before
do
cluster
.
gcp_token
=
'tmp'
cluster
.
gcp_operation_id
=
'tmp'
cluster
.
make_created!
end
it
'nullify gcp_token and gcp_operation_id'
do
expect
(
cluster
.
gcp_token
).
to
be_nil
expect
(
cluster
.
gcp_operation_id
).
to
be_nil
expect
(
cluster
).
to
be_created
end
end
context
'when transits to errored state'
do
let
(
:reason
)
{
'something wrong'
}
before
do
cluster
.
make_errored!
(
reason
)
end
it
'sets status_reason'
do
expect
(
cluster
.
status_reason
).
to
eq
(
reason
)
expect
(
cluster
).
to
be_errored
end
end
end
describe
'#project_namespace_placeholder'
do
subject
{
cluster
.
project_namespace_placeholder
}
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
it
'returns a placeholder'
do
is_expected
.
to
eq
(
"
#{
cluster
.
project
.
path
}
-
#{
cluster
.
project
.
id
}
"
)
end
end
describe
'#on_creation?'
do
subject
{
cluster
.
on_creation?
}
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
context
'when status is creating'
do
before
do
cluster
.
make_creating!
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when status is created'
do
before
do
cluster
.
make_created!
end
it
{
is_expected
.
to
be_falsey
}
end
end
describe
'#api_url'
do
subject
{
cluster
.
api_url
}
let
(
:cluster
)
{
create
(
:gcp_cluster
,
:created_on_gke
)
}
let
(
:api_url
)
{
'https://'
+
cluster
.
endpoint
}
it
{
is_expected
.
to
eq
(
api_url
)
}
end
describe
'#restrict_modification'
do
subject
{
cluster
.
restrict_modification
}
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
context
'when status is created'
do
before
do
cluster
.
make_created!
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when status is creating'
do
before
do
cluster
.
make_creating!
end
it
{
is_expected
.
to
be_falsey
}
it
'sets error'
do
is_expected
.
to
be_falsey
expect
(
cluster
.
errors
).
not_to
be_empty
end
end
end
describe
'#destroy'
do
subject
{
cluster
.
destroy
}
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
context
'when status is created'
do
before
do
cluster
.
make_created!
end
it
'destory the cluster'
do
is_expected
.
to
eq
(
cluster
)
end
end
context
'when status is creating'
do
before
do
cluster
.
make_creating!
end
it
'does not destory the cluster'
do
is_expected
.
to
be_nil
end
end
end
end
spec/services/ci/create_cluster_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
CreateClusterService
do
describe
'#execute'
do
let
(
:access_token
)
{
'xxx'
}
context
'when correct params'
do
it
'creates a cluster object'
do
end
end
context
'when invalid params'
do
it
'returns an error'
do
end
end
end
end
spec/services/ci/fetch_gcp_operation_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
FetchGcpOperationService
do
describe
'#execute'
do
context
'when correct params'
do
it
'fetch the gcp operaion'
do
end
end
context
'when invalid params'
do
it
'sets an error to cluster object'
do
end
end
end
end
spec/services/ci/fetch_kubernetes_token_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
FetchKubernetesTokenService
do
describe
'#execute'
do
context
'when correct params'
do
it
'fetch the kubernetes token'
do
end
end
context
'when invalid params'
do
it
'returns nil'
do
end
end
end
end
spec/services/ci/finalize_cluster_creation_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
FinalizeClusterCreationService
do
describe
'#execute'
do
context
'when correct params'
do
it
'execute IntegrateClusterService'
do
end
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
end
end
end
end
spec/services/ci/integrate_cluster_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
IntegrateClusterService
do
describe
'#execute'
do
context
'when correct params'
do
it
'creates a cluster object'
do
end
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
end
end
end
end
spec/services/ci/provision_cluster_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
ProvisionClusterService
do
describe
'#execute'
do
context
'when correct params'
do
it
'creates a cluster on gke'
do
end
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
end
end
end
end
spec/services/ci/update_cluster_service_spec.rb
0 → 100644
View file @
a644f4b8
require
'spec_helper'
describe
Ci
::
UpdateClusterService
do
describe
'#execute'
do
context
'when correct params'
do
it
'updates the cluster and the service'
do
end
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
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