Commit 55fc5bd9 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

organizing test suite

parent fb09f30e
build/ build/
.cproject .cproject
.project .project
.settings/**
test/.bundle test/.bundle
test/tmp/**
test/logs/**
...@@ -6,12 +6,32 @@ GEM ...@@ -6,12 +6,32 @@ GEM
open4 open4
Platform (0.4.0) Platform (0.4.0)
addressable (2.2.2) addressable (2.2.2)
archive-tar-minitar (0.5.2)
columnize (0.3.2)
em-http-request (0.2.14) em-http-request (0.2.14)
addressable (>= 2.0.0) addressable (>= 2.0.0)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
eventmachine (0.12.10) eventmachine (0.12.10)
json (1.4.3) json (1.4.3)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
open4 (1.0.1) open4 (1.0.1)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
PLATFORMS PLATFORMS
ruby ruby
...@@ -20,3 +40,5 @@ DEPENDENCIES ...@@ -20,3 +40,5 @@ DEPENDENCIES
POpen4 (= 0.1.4) POpen4 (= 0.1.4)
em-http-request (= 0.2.14) em-http-request (= 0.2.14)
json (= 1.4.3) json (= 1.4.3)
ruby-debug
ruby-debug19
require 'rubygems' require 'rubygems'
require 'popen4' require 'popen4'
require 'tmpdir'
require 'erb' require 'erb'
require 'ftools' require 'fileutils'
require 'ruby-debug' require 'ruby-debug'
require 'test/unit' require 'test/unit'
require 'em-http' require 'em-http'
...@@ -10,9 +9,10 @@ require 'json' ...@@ -10,9 +9,10 @@ require 'json'
module BaseTestCase module BaseTestCase
def setup def setup
create_dirs
default_configuration default_configuration
@test_config_file = "#{self.method_name}.conf" @test_config_file = "#{test_method_name}.conf"
config_test_name = "config_#{self.method_name}" config_test_name = "config_#{test_method_name}"
self.send(config_test_name) if self.respond_to?(config_test_name) self.send(config_test_name) if self.respond_to?(config_test_name)
unless @disable_start_stop_server unless @disable_start_stop_server
...@@ -27,10 +27,11 @@ module BaseTestCase ...@@ -27,10 +27,11 @@ module BaseTestCase
self.stop_server self.stop_server
self.delete_config_file self.delete_config_file
end end
delete_dirs
end end
def nginx_executable def nginx_executable
return ENV['NGINX_EXEC'].nil? ? "/usr/local/nginxpushstream/source/nginx/objs/nginx" : ENV['NGINX_EXEC'] return ENV['NGINX_EXEC'].nil? ? "/usr/local/nginx/sbin/nginx" : ENV['NGINX_EXEC']
end end
def nginx_address def nginx_address
...@@ -51,7 +52,7 @@ module BaseTestCase ...@@ -51,7 +52,7 @@ module BaseTestCase
def start_server def start_server
error_message = "" error_message = ""
status = POpen4::popen4("#{ nginx_executable } -c #{ Dir.tmpdir }/#{ @test_config_file }") do |stdout, stderr, stdin, pid| status = POpen4::popen4("#{ nginx_executable } -c #{ config_filename }") do |stdout, stderr, stdin, pid|
error_message = stderr.read.strip unless stderr.eof error_message = stderr.read.strip unless stderr.eof
return error_message unless error_message.nil? return error_message unless error_message.nil?
end end
...@@ -60,7 +61,7 @@ module BaseTestCase ...@@ -60,7 +61,7 @@ module BaseTestCase
def stop_server def stop_server
error_message = "" error_message = ""
status = POpen4::popen4("#{ nginx_executable } -c #{ Dir.tmpdir }/#{ @test_config_file } -s stop") do |stdout, stderr, stdin, pid| status = POpen4::popen4("#{ nginx_executable } -c #{ config_filename } -s stop") do |stdout, stderr, stdin, pid|
error_message = stderr.read.strip unless stderr.eof error_message = stderr.read.strip unless stderr.eof
return error_message unless error_message.nil? return error_message unless error_message.nil?
end end
...@@ -70,13 +71,35 @@ module BaseTestCase ...@@ -70,13 +71,35 @@ module BaseTestCase
def create_config_file def create_config_file
template = ERB.new @@config_template template = ERB.new @@config_template
config_content = template.result(binding) config_content = template.result(binding)
File.open(Dir.tmpdir + "/#{ @test_config_file }", 'w') {|f| f.write(config_content) } File.open(config_filename, 'w') {|f| f.write(config_content) }
File.open(Dir.tmpdir + "/mime.types", 'w') {|f| f.write(@@mime_tipes_template) } File.open(mime_types_filename, 'w') {|f| f.write(@@mime_tipes_template) }
end end
def delete_config_file def delete_config_file
File.delete(Dir.tmpdir + "/#{ @test_config_file }") File.delete(config_filename)
File.delete(Dir.tmpdir + "/mime.types") File.delete(mime_types_filename)
end
def create_dirs
FileUtils.mkdir('tmp') unless File.exist?('tmp') and File.directory?('tmp')
FileUtils.mkdir('logs') unless File.exist?('logs') and File.directory?('logs')
end
def delete_dirs
FileUtils.rm_rf('tmp') if File.exist?('tmp') and File.directory?('tmp')
FileUtils.rm_rf('logs') if File.exist?('logs') and File.directory?('logs')
end
def config_filename
File.expand_path("tmp/#{ @test_config_file }")
end
def mime_types_filename
File.expand_path("tmp/mime.types")
end
def test_method_name
self.respond_to?('method_name') ? self.method_name : self.__name__
end end
def time_diff_milli(start, finish) def time_diff_milli(start, finish)
...@@ -142,8 +165,8 @@ module BaseTestCase ...@@ -142,8 +165,8 @@ module BaseTestCase
end end
@@config_template = %q{ @@config_template = %q{
pid logs/nginx.pid; pid <%= File.expand_path("logs/nginx.pid") %>;
error_log logs/nginx-main_error.log debug; error_log <%= File.expand_path("logs/nginx-main_error.log") %> debug;
# Development Mode # Development Mode
master_process off; master_process off;
daemon off; daemon off;
...@@ -158,8 +181,8 @@ http { ...@@ -158,8 +181,8 @@ http {
include mime.types; include mime.types;
default_type application/octet-stream; default_type application/octet-stream;
access_log logs/nginx-http_access.log; access_log <%= File.expand_path("logs/nginx-http_access.log")%>;
error_log logs/nginx-http_error.log debug; error_log <%= File.expand_path("logs/nginx-http_error.log")%> debug;
tcp_nopush on; tcp_nopush on;
tcp_nodelay on; tcp_nodelay on;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment