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
35487a1e
Commit
35487a1e
authored
Jan 25, 2020
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@master
parent
4f749a9b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
6 deletions
+72
-6
app/models/serverless/domain_cluster.rb
app/models/serverless/domain_cluster.rb
+7
-2
lib/gitlab/prometheus/queries/knative_invocation_query.rb
lib/gitlab/prometheus/queries/knative_invocation_query.rb
+1
-1
lib/gitlab/serverless/domain.rb
lib/gitlab/serverless/domain.rb
+13
-0
spec/factories/serverless/domain_cluster.rb
spec/factories/serverless/domain_cluster.rb
+0
-1
spec/lib/gitlab/serverless/domain_spec.rb
spec/lib/gitlab/serverless/domain_spec.rb
+22
-0
spec/models/serverless/domain_cluster_spec.rb
spec/models/serverless/domain_cluster_spec.rb
+29
-2
No files found.
app/models/serverless/domain_cluster.rb
View file @
35487a1e
...
@@ -4,11 +4,16 @@ module Serverless
...
@@ -4,11 +4,16 @@ module Serverless
class
DomainCluster
<
ApplicationRecord
class
DomainCluster
<
ApplicationRecord
self
.
table_name
=
'serverless_domain_cluster'
self
.
table_name
=
'serverless_domain_cluster'
HEX_REGEXP
=
%r{
\A\h
+
\z
}
.
freeze
belongs_to
:pages_domain
belongs_to
:pages_domain
belongs_to
:knative
,
class_name:
'Clusters::Applications::Knative'
,
foreign_key:
'clusters_applications_knative_id'
belongs_to
:knative
,
class_name:
'Clusters::Applications::Knative'
,
foreign_key:
'clusters_applications_knative_id'
belongs_to
:creator
,
class_name:
'User'
,
optional:
true
belongs_to
:creator
,
class_name:
'User'
,
optional:
true
validates
:pages_domain
,
:knative
,
:uuid
,
presence:
true
validates
:pages_domain
,
:knative
,
presence:
true
validates
:uuid
,
uniqueness:
true
,
length:
{
is:
14
}
validates
:uuid
,
presence:
true
,
uniqueness:
true
,
length:
{
is:
Gitlab
::
Serverless
::
Domain
::
UUID_LENGTH
},
format:
{
with:
HEX_REGEXP
,
message:
'only allows hex characters'
}
default_value_for
(
:uuid
,
allows_nil:
false
)
{
Gitlab
::
Serverless
::
Domain
.
generate_uuid
}
end
end
end
end
lib/gitlab/prometheus/queries/knative_invocation_query.rb
View file @
35487a1e
...
@@ -20,7 +20,7 @@ module Gitlab
...
@@ -20,7 +20,7 @@ module Gitlab
protected
protected
def
context
(
function_id
)
def
context
(
function_id
)
function
=
Serverless
::
Function
.
find_by_id
(
function_id
)
function
=
::
Serverless
::
Function
.
find_by_id
(
function_id
)
{
{
function_name:
function
.
name
,
function_name:
function
.
name
,
kube_namespace:
function
.
namespace
kube_namespace:
function
.
namespace
...
...
lib/gitlab/serverless/domain.rb
0 → 100644
View file @
35487a1e
# frozen_string_literal: true
module
Gitlab
module
Serverless
class
Domain
UUID_LENGTH
=
14
def
self
.
generate_uuid
SecureRandom
.
hex
(
UUID_LENGTH
/
2
)
end
end
end
end
spec/factories/serverless/domain_cluster.rb
View file @
35487a1e
...
@@ -5,6 +5,5 @@ FactoryBot.define do
...
@@ -5,6 +5,5 @@ FactoryBot.define do
pages_domain
{
create
(
:pages_domain
)
}
pages_domain
{
create
(
:pages_domain
)
}
knative
{
create
(
:clusters_applications_knative
)
}
knative
{
create
(
:clusters_applications_knative
)
}
creator
{
create
(
:user
)
}
creator
{
create
(
:user
)
}
uuid
{
SecureRandom
.
hex
(
7
)
}
end
end
end
end
spec/lib/gitlab/serverless/domain_spec.rb
0 → 100644
View file @
35487a1e
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Serverless
::
Domain
do
describe
'.generate_uuid'
do
it
'has 14 characters'
do
expect
(
described_class
.
generate_uuid
.
length
).
to
eq
(
described_class
::
UUID_LENGTH
)
end
it
'consists of only hexadecimal characters'
do
expect
(
described_class
.
generate_uuid
).
to
match
(
/\A\h+\z/
)
end
it
'uses random characters'
do
uuid
=
'abcd1234567890'
expect
(
SecureRandom
).
to
receive
(
:hex
).
with
(
described_class
::
UUID_LENGTH
/
2
).
and_return
(
uuid
)
expect
(
described_class
.
generate_uuid
).
to
eq
(
uuid
)
end
end
end
spec/models/serverless/domain_cluster_spec.rb
View file @
35487a1e
...
@@ -8,10 +8,17 @@ describe Serverless::DomainCluster do
...
@@ -8,10 +8,17 @@ describe Serverless::DomainCluster do
describe
'validations'
do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:pages_domain
)
}
it
{
is_expected
.
to
validate_presence_of
(
:pages_domain
)
}
it
{
is_expected
.
to
validate_presence_of
(
:knative
)
}
it
{
is_expected
.
to
validate_presence_of
(
:knative
)
}
it
{
is_expected
.
to
validate_presence_of
(
:uuid
)
}
it
{
is_expected
.
to
validate_presence_of
(
:uuid
)
}
it
{
is_expected
.
to
validate_length_of
(
:uuid
).
is_equal_to
(
Gitlab
::
Serverless
::
Domain
::
UUID_LENGTH
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:uuid
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:uuid
)
}
it
{
is_expected
.
to
validate_length_of
(
:uuid
).
is_equal_to
(
14
)
}
it
'validates that uuid has only hex characters'
do
subject
=
build
(
:serverless_domain_cluster
,
uuid:
'z1234567890123'
)
subject
.
valid?
expect
(
subject
.
errors
[
:uuid
]).
to
include
(
'only allows hex characters'
)
end
end
end
describe
'associations'
do
describe
'associations'
do
...
@@ -19,4 +26,24 @@ describe Serverless::DomainCluster do
...
@@ -19,4 +26,24 @@ describe Serverless::DomainCluster do
it
{
is_expected
.
to
belong_to
(
:knative
)
}
it
{
is_expected
.
to
belong_to
(
:knative
)
}
it
{
is_expected
.
to
belong_to
(
:creator
).
optional
}
it
{
is_expected
.
to
belong_to
(
:creator
).
optional
}
end
end
describe
'uuid'
do
context
'when nil'
do
it
'generates a value by default'
do
attributes
=
build
(
:serverless_domain_cluster
).
attributes
.
merge
(
uuid:
nil
)
expect
(
Gitlab
::
Serverless
::
Domain
).
to
receive
(
:generate_uuid
).
and_call_original
subject
=
Serverless
::
DomainCluster
.
new
(
attributes
)
expect
(
subject
.
uuid
).
not_to
be_blank
end
end
context
'when not nil'
do
it
'does not override the existing value'
do
uuid
=
'abcd1234567890'
expect
(
build
(
:serverless_domain_cluster
,
uuid:
uuid
).
uuid
).
to
eq
(
uuid
)
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