/
Rakefile
43 lines (36 loc) · 1.19 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'rake/testtask'
require 'rest_client'
Rake::TestTask.new do |t|
t.libs = ['lib', 'test']
t.pattern = 'test/**/test_*.rb'
end
desc "Run tests"
task :default => :test
namespace :db do
DB_HOST = 'localhost'
DB_PORT = 2480
DB_NAME = 'temp'
DB_ROOT_USER = 'root'
DB_ROOT_PASS = ENV['ORIENTDB_ROOT_PASS'] || 'root'
desc 'Check whether a test DB exists and create if not'
task :setup4test do
found = true
begin
::RestClient::Request.new({:url=>"http://#{DB_HOST}:#{DB_PORT}/database/#{DB_NAME}", :method=>:get, :user=>DB_ROOT_USER, :password=>DB_ROOT_PASS}).execute
rescue Errno::ECONNREFUSED
fail "server seems to be closed, not running on #{DB_HOST}:#{DB_PORT}?"
rescue ::RestClient::Unauthorized
# this is expected reaction if DB does not exist
puts 'DB does NOT exist -> create'
found = false
rescue ::RestClient::Exception => e
fail "unexpected failure: #{e}"
end
if found
puts 'DB already exists'
else
::RestClient::Request.new({:url=>"http://#{DB_HOST}:#{DB_PORT}/database/#{DB_NAME}/memory", :method=>:post, :user=>DB_ROOT_USER, :password=>DB_ROOT_PASS}).execute
puts 'DB created'
end
end
end