Class: Castanet::Testing::CallbackServerTasks

Inherits:
Object
  • Object
show all
Extended by:
AssetPaths
Includes:
CommonTasks, Namespacing, Rake::DSL
Defined in:
lib/castanet/testing/callback_server_tasks.rb

Constant Summary collapse

DEFAULT_SCRATCH_DIR =
'/tmp/castanet-testing/callback'
DEFAULT_HOST =
'localhost'
DEFAULT_SSL_KEY =
ssl_key_path
DEFAULT_SSL_CERT =
ssl_cert_path
DEFAULT_TIMEOUT =
120
CALLBACK_PATH =
asset_path('callback/callback.rb')
RUNNER =
asset_path('run.rb')

Constants included from ConnectionTesting

Castanet::Testing::ConnectionTesting::LOGGER

Instance Method Summary collapse

Methods included from AssetPaths

asset_path, ssl_cert_path, ssl_key_path

Methods included from Namespacing

#namespaces

Methods included from CommonTasks

#clean_all, #wait_all

Methods included from ConnectionTesting

#responding?

Constructor Details

#initialize(options = {}) ⇒ CallbackServerTasks

Returns a new instance of CallbackServerTasks.

Parameters:

  • opts (Hash)

    a customizable set of options



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/castanet/testing/callback_server_tasks.rb', line 32

def initialize(options = {})
  root = options[:root] || 'castanet:testing:callback'
  scratch_dir = options[:scratch_dir] || DEFAULT_SCRATCH_DIR
  host = options[:host] || DEFAULT_HOST
  ssl_cert = options[:ssl_cert] || DEFAULT_SSL_CERT
  ssl_key = options[:ssl_key] || DEFAULT_SSL_KEY
  timeout = options[:timeout] || DEFAULT_TIMEOUT

  port = ENV['PORT']
  instance_dir = "#{scratch_dir}/callback.#{$$}"

  namespaces(root.split(':')) do
    file instance_dir do
      mkdir_p instance_dir
    end

    task :ensure_port do
      raise "PORT is not set" unless port
    end

    task :prep => [:ensure_port, instance_dir]

    desc 'Start a CAS proxy callback instance (requires PORT to be set)'
    task :start => :prep do
      ENV['HOST'] = host
      ENV['SSL_CERT_PATH'] = ssl_cert
      ENV['SSL_KEY_PATH'] = ssl_key

      cd(instance_dir) { load(CALLBACK_PATH) }
    end

    desc "Wait for all CAS proxy callback instances in #{scratch_dir} to become ready"
    task(:waitall) { wait_all(scratch_dir, timeout) }

    desc "Clean up all CAS proxy callback instances under #{scratch_dir}"
    task(:cleanall) { clean_all(scratch_dir, 'callback') }

    desc "Delete #{scratch_dir}"
    task :delete_scratch_dir do
      rm_rf scratch_dir
    end
  end
end