Class: Urushiol::VarnishTestBase
- Inherits:
-
Object
- Object
- Urushiol::VarnishTestBase
- Defined in:
- lib/urushiol.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #client_testcase(name = "c", config = "") {|test| ... } ⇒ Object
- #create_test_file(vtc) ⇒ Object
- #define_tests(tests) ⇒ Object
- #delay(time) ⇒ Object
- #get_vcl ⇒ Object
-
#initialize(name, vcl_file_ref = nil) ⇒ VarnishTestBase
constructor
A new instance of VarnishTestBase.
- #mock_backends(source = @vcl_source) ⇒ Object
- #mock_server(name) {|server| ... } ⇒ Object
- #mock_varnish(name) {|varnish| ... } ⇒ Object
- #override_vcl_file(vcl_file) ⇒ Object
- #run ⇒ Object
- #server(&block) ⇒ Object
Constructor Details
#initialize(name, vcl_file_ref = nil) ⇒ VarnishTestBase
Returns a new instance of VarnishTestBase.
9 10 11 12 |
# File 'lib/urushiol.rb', line 9 def initialize (name,vcl_file_ref=nil) @vtc_obj = Vtc.new(name) @vcl_source = vcl_file_ref end |
Instance Method Details
#cleanup ⇒ Object
85 86 87 |
# File 'lib/urushiol.rb', line 85 def cleanup #system("rm /tmp/test.vtc") end |
#client_testcase(name = "c", config = "") {|test| ... } ⇒ Object
38 39 40 41 42 |
# File 'lib/urushiol.rb', line 38 def client_testcase(name="c",config="",&block) test = ClientTestBase.new(name,config) yield test if block_given? @vtc_obj.append_config(test.test_source) end |
#create_test_file(vtc) ⇒ Object
50 51 52 |
# File 'lib/urushiol.rb', line 50 def create_test_file(vtc) File.open('/tmp/test.vtc', "wb") { |f| f.write(vtc.get_spec) } end |
#define_tests(tests) ⇒ Object
34 35 36 |
# File 'lib/urushiol.rb', line 34 def define_tests(tests) @vtc_obj.mock_clients_and_tests(tests) end |
#delay(time) ⇒ Object
62 63 64 |
# File 'lib/urushiol.rb', line 62 def delay(time) @vtc_obj.append_config("\ndelay #{time}") end |
#get_vcl ⇒ Object
58 59 60 |
# File 'lib/urushiol.rb', line 58 def get_vcl @vcl_source end |
#mock_backends(source = @vcl_source) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/urushiol.rb', line 20 def mock_backends(source=@vcl_source) if source != nil @vtc_obj.mock_backends(Vcl.new(source).get_conf) else puts "\nCan't mock backends if no VCL file is specified.\n" end end |
#mock_server(name) {|server| ... } ⇒ Object
44 45 46 47 48 |
# File 'lib/urushiol.rb', line 44 def mock_server(name,&block) server = Server.new(name) yield server if block_given? @vtc_obj.append_config(server.server_source) end |
#mock_varnish(name) {|varnish| ... } ⇒ Object
14 15 16 17 18 |
# File 'lib/urushiol.rb', line 14 def mock_varnish(name) varnish = Varnish.new(name) yield varnish if block_given? @vtc_obj.append_config(varnish.varnish_source) end |
#override_vcl_file(vcl_file) ⇒ Object
54 55 56 |
# File 'lib/urushiol.rb', line 54 def override_vcl_file(vcl_file) File.open('/tmp/test.vcl', "wb") { |f| f.write(Vcl.new(vcl_file).get_conf) } end |
#run ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/urushiol.rb', line 66 def run create_test_file(@vtc_obj) varnishd_check = `which varnishd` ; result=$?.success? if result == true output=`varnishtest /tmp/test.vtc` ; result=$?.success? if result == false puts output puts "\nVarnishtests returned errors, see stack trace above." exit 1 else puts "Test completed successfully without errors." end cleanup else puts "Varnish does not seem to be installed on your computer. Urushiol can't run without Varnish" end end |
#server(&block) ⇒ Object
28 29 30 31 32 |
# File 'lib/urushiol.rb', line 28 def server(&block) if block_given? @vtc_obj.append_config(yield Server) end end |