Skip to content

Commit ff80100

Browse files
committed
test-config: dynamically build test.conf to provide absolute paths
redis config requires absolute paths for pidfile, unixsocket, and logfile directives, and interprets relative paths incorrectly without errors. Dynamically build the test.conf from an erb file if it is not present. This has the side-effect of creating a single source of truth for these values. Resolves #439
1 parent d15b396 commit ff80100

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/rdsrv
1010
/redis/*
1111
/test/db
12+
/test/test.conf

Rakefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ENV["REDIS_BRANCH"] ||= "unstable"
55
REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
66
REDIS_CNF = File.join(REDIS_DIR, "test.conf")
77
REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
8+
REDIS_LOG = File.join(REDIS_DIR, "db", "redis.log")
9+
REDIS_SOCKET = File.join(REDIS_DIR, "db", "redis.sock")
810
BINARY = "tmp/redis-#{ENV["REDIS_BRANCH"]}/src/redis-server"
911

1012
task :default => :run
@@ -13,7 +15,7 @@ desc "Run tests and manage server start/stop"
1315
task :run => [:start, :test, :stop]
1416

1517
desc "Start the Redis server"
16-
task :start => BINARY do
18+
task :start => [BINARY, REDIS_CNF] do
1719
sh "#{BINARY} --version"
1820

1921
redis_running = \
@@ -46,6 +48,7 @@ end
4648
desc "Clean up testing artifacts"
4749
task :clean do
4850
FileUtils.rm_f(BINARY)
51+
FileUtils.rm_f(REDIS_CNF)
4952
end
5053

5154
file BINARY do
@@ -62,6 +65,19 @@ file BINARY do
6265
SH
6366
end
6467

68+
file REDIS_CNF do
69+
require 'erb'
70+
template_path = "#{REDIS_CNF}.erb"
71+
template = File.read("#{REDIS_CNF}.erb")
72+
File.open(REDIS_CNF, 'w') do |file|
73+
file.puts "\# This file was auto-generated at #{Time.now}",
74+
"\# from (#{"#{REDIS_CNF}.erb"})",
75+
"\#"
76+
conf = ERB.new(template).result
77+
file << conf
78+
end
79+
end
80+
6581
Rake::TestTask.new do |t|
6682
t.options = "-v" if $VERBOSE
6783
t.test_files = FileList["test/*_test.rb"]

test/test.conf

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/test.conf.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dir <%= REDIS_DIR %>
2+
pidfile <%= REDIS_PID %>
3+
port 6381
4+
unixsocket <%= REDIS_SOCKET %>
5+
timeout 300
6+
loglevel debug
7+
logfile <%= REDIS_LOG %>
8+
databases 16
9+
daemonize yes

0 commit comments

Comments
 (0)