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
Tatuya Kamada
gitlab-ce
Commits
ef604388
Commit
ef604388
authored
Nov 27, 2015
by
Gabriel Mazetto
Committed by
Gabriel Mazetto
Aug 04, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs for RedisConfig
Make sure :url is not present on RedisConfig.params after parsing
parent
926cee00
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
125 additions
and
1 deletion
+125
-1
lib/gitlab/redis.rb
lib/gitlab/redis.rb
+1
-1
spec/fixtures/config/redis_new_format_host.yml
spec/fixtures/config/redis_new_format_host.yml
+29
-0
spec/fixtures/config/redis_new_format_socket.yml
spec/fixtures/config/redis_new_format_socket.yml
+6
-0
spec/fixtures/config/redis_old_format_host.yml
spec/fixtures/config/redis_old_format_host.yml
+5
-0
spec/fixtures/config/redis_old_format_socket.yml
spec/fixtures/config/redis_old_format_socket.yml
+3
-0
spec/lib/gitlab/redis_config_spec.rb
spec/lib/gitlab/redis_config_spec.rb
+81
-0
No files found.
lib/gitlab/redis.rb
View file @
ef604388
...
...
@@ -54,12 +54,12 @@ module Gitlab
if
redis_uri
.
scheme
==
'unix'
# Redis::Store does not handle Unix sockets well, so let's do it for them
config
[
:path
]
=
redis_uri
.
path
config
.
delete
(
:url
)
else
redis_hash
=
::
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
redis_uri
)
config
.
merge!
(
redis_hash
)
end
config
.
delete
(
:url
)
config
end
...
...
spec/fixtures/config/redis_new_format_host.yml
0 → 100644
View file @
ef604388
# redis://[:password@]host[:port][/db-number][?option=value]
# more details: http://www.iana.org/assignments/uri-schemes/prov/redis
development
:
url
:
redis://:mypassword@localhost:6379/99
sentinels
:
-
host
:
localhost
port
:
26380
# point to sentinel, not to redis port
-
host
:
slave2
port
:
26381
# point to sentinel, not to redis port
test
:
url
:
redis://:mypassword@localhost:6379/99
sentinels
:
-
host
:
localhost
port
:
26380
# point to sentinel, not to redis port
-
host
:
slave2
port
:
26381
# point to sentinel, not to redis port
production
:
url
:
redis://:mypassword@localhost:6379/99
sentinels
:
-
host
:
slave1
port
:
26380
# point to sentinel, not to redis port
-
host
:
slave2
port
:
26381
# point to sentinel, not to redis port
spec/fixtures/config/redis_new_format_socket.yml
0 → 100644
View file @
ef604388
development
:
url
:
unix:/path/to/redis.sock
test
:
url
:
unix:/path/to/redis.sock
production
:
url
:
unix:/path/to/redis.sock
spec/fixtures/config/redis_old_format_host.yml
0 → 100644
View file @
ef604388
# redis://[:password@]host[:port][/db-number][?option=value]
# more details: http://www.iana.org/assignments/uri-schemes/prov/redis
development
:
redis://:mypassword@localhost:6379/99
test
:
redis://:mypassword@localhost:6379/99
production
:
redis://:mypassword@localhost:6379/99
spec/fixtures/config/redis_old_format_socket.yml
0 → 100644
View file @
ef604388
development
:
unix:/path/to/redis.sock
test
:
unix:/path/to/redis.sock
production
:
unix:/path/to/redis.sock
spec/lib/gitlab/redis_config_spec.rb
0 → 100644
View file @
ef604388
require
'spec_helper'
describe
Gitlab
::
RedisConfig
do
let
(
:redis_config
)
{
Rails
.
root
.
join
(
'config'
,
'resque.yml'
)
}
describe
'.params'
do
subject
{
described_class
.
params
}
context
'when url contains unix socket reference'
do
let
(
:config_old
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_old_format_socket.yml'
)
}
let
(
:config_new
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_new_format_socket.yml'
)
}
context
'with old format'
do
it
'returns path key instead'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_old
}
is_expected
.
to
include
(
path:
'/path/to/redis.sock'
)
is_expected
.
not_to
have_key
(
:url
)
end
end
context
'with new format'
do
it
'returns path key instead'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_new
}
is_expected
.
to
include
(
path:
'/path/to/redis.sock'
)
is_expected
.
not_to
have_key
(
:url
)
end
end
end
context
'when url is host based'
do
let
(
:config_old
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_old_format_host.yml'
)
}
let
(
:config_new
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_new_format_host.yml'
)
}
context
'with old format'
do
it
'returns hash with host, port, db, and password'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_old
}
is_expected
.
to
include
(
host:
'localhost'
,
password:
'mypassword'
,
port:
6379
,
db:
99
)
is_expected
.
not_to
have_key
(
:url
)
end
end
context
'with new format'
do
it
'returns hash with host, port, db, and password'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_new
}
is_expected
.
to
include
(
host:
'localhost'
,
password:
'mypassword'
,
port:
6379
,
db:
99
)
is_expected
.
not_to
have_key
(
:url
)
end
end
end
end
describe
'.raw_params'
do
subject
{
described_class
.
send
(
:raw_params
)
}
it
'returns default redis url when no config file is present'
do
expect
(
Gitlab
::
RedisConfig
).
to
receive
(
:fetch_config
)
{
false
}
is_expected
.
to
eq
(
url:
Gitlab
::
RedisConfig
::
DEFAULT_REDIS_URL
)
end
it
'returns old-style single url config in a hash'
do
expect
(
Gitlab
::
RedisConfig
).
to
receive
(
:fetch_config
)
{
'redis://myredis:6379'
}
is_expected
.
to
eq
(
url:
'redis://myredis:6379'
)
end
end
describe
'.fetch_config'
do
subject
{
described_class
.
send
(
:fetch_config
)
}
it
'returns false when no config file is present'
do
allow
(
File
).
to
receive
(
:exists?
).
with
(
redis_config
)
{
false
}
is_expected
.
to
be_falsey
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