/test/ppane/runner_test.rb

http://github.com/tgunr/passengerpane · Ruby · 141 lines · 123 code · 18 blank · 0 comment · 4 complexity · 03cd1e3182ef74872dc0243aaf584877 MD5 · raw file

  1. require File.expand_path('../test_helper', __FILE__)
  2. describe "Runner" do
  3. before do
  4. use_fake_apache_directory
  5. application_directory = File.join(temporary_directory, 'app')
  6. %w(app public).each do |directory|
  7. FileUtils.mkdir_p(File.join(application_directory, directory))
  8. end
  9. @conf = PassengerPane::Configuration.new(fake_apache_directory)
  10. @app = PassengerPane::Application.new(@conf, :path => application_directory)
  11. PassengerPane::Configuration.stubs(:auto).returns(@conf)
  12. end
  13. it "lists all configured applications" do
  14. output = capture_stdout do
  15. PassengerPane::Runner.run({}, %w(list))
  16. end
  17. @conf.applications.each do |app|
  18. output.should.include?(app.host)
  19. end
  20. end
  21. it "registers all configured hostnames" do
  22. @conf.applications.each do |app|
  23. PassengerPane::DirectoryServices.expects(:register).with(app.to_hash['hosts'])
  24. end
  25. capture_stdout do
  26. PassengerPane::Runner.run({}, %w(register))
  27. end
  28. end
  29. it "shows information about the system" do
  30. @conf.httpd.stubs(:passenger_module_installed?).returns(true)
  31. PassengerPane::DirectoryServices.stubs(:registered_hosts).returns(%w(assets.skit.local skit.local weblog.local))
  32. output = capture_stdout do
  33. PassengerPane::Runner.run({}, %w(info))
  34. end
  35. output.should.include('Passenger installed: yes')
  36. output.should.include('Passenger Pane configured: yes')
  37. end
  38. it "shows information about the system in JSON" do
  39. @conf.httpd.stubs(:passenger_module_installed?).returns(true)
  40. PassengerPane::DirectoryServices.stubs(:registered_hosts).returns(%w(assets.skit.local skit.local weblog.local))
  41. output = capture_stdout do
  42. PassengerPane::Runner.run({'m' => nil}, %w(info))
  43. end
  44. output.should.include('"passenger_pane_configured":true')
  45. output.should.include('"passenger_module_installed":true')
  46. end
  47. it "configures Apache for use with the Passenger Pane" do
  48. Kernel.allow_backtick = true
  49. @conf.httpd.stubs(:restart)
  50. File.open(@conf.httpd.filename, 'w') { |file| file.write('') }
  51. capture_stdout do
  52. PassengerPane::Runner.run({}, %w(configure))
  53. end
  54. @conf.httpd.should.be.passenger_pane_configured
  55. end
  56. it "does not configure Apache for use with the Passenger Pane if it's already configured" do
  57. @conf.httpd.expects(:write).never
  58. capture_stdout do
  59. PassengerPane::Runner.run({}, %w(configure))
  60. end
  61. end
  62. it "adds a new application to the configuration" do
  63. PassengerPane::DirectoryServices.expects(:register).with(%w(app.local))
  64. capture_stdout do
  65. PassengerPane::Runner.run({}, ['add', @app.path])
  66. end
  67. @conf.applications.map { |app| app.host }.should.include('app.local')
  68. end
  69. it "updates an application" do
  70. @conf.httpd.stubs(:restart)
  71. PassengerPane::DirectoryServices.expects(:register).with(%w(blog.local)).returns(true)
  72. PassengerPane::DirectoryServices.expects(:unregister).with(%w(staging.blog.local)).returns(true)
  73. app = PassengerPane::Application.find(@conf, :host => 'staging.blog.local')
  74. capture_stdout do
  75. PassengerPane::Runner.run({'host' => 'blog.local'}, ['update', app.host])
  76. end
  77. app.contents = nil
  78. app._parse
  79. app.host.should == 'blog.local'
  80. end
  81. it "deletes an application" do
  82. @conf.httpd.stubs(:restart)
  83. PassengerPane::DirectoryServices.expects(:unregister).with(%w(staging.blog.local)).returns(true)
  84. app = PassengerPane::Application.find(@conf, :host => 'staging.blog.local')
  85. capture_stdout do
  86. PassengerPane::Runner.run({}, ['delete', app.host])
  87. end
  88. File.should.not.exist?(app.config_filename)
  89. end
  90. it "restarts an application" do
  91. PassengerPane::DirectoryServices.stubs(:register).returns(true)
  92. @app.should.save
  93. File.should.not.exist?(File.join(@app.path, 'tmp', 'restart.txt'))
  94. capture_stdout do
  95. PassengerPane::Runner.run({}, ['restart', @app.host])
  96. end
  97. File.should.exist?(File.join(@app.path, 'tmp', 'restart.txt'))
  98. end
  99. it "does not restart an application that doesn't exist" do
  100. capture_stderr do
  101. PassengerPane::Runner.run({}, ['restart', 'unknown'])
  102. end.should == "[!] Can't find application with hostname `unknown'\n"
  103. end
  104. it "restarts Apache" do
  105. @conf.httpd.expects(:valid?).returns(true)
  106. @conf.httpd.expects(:system).with(@conf.apache_restart_command).returns(true)
  107. capture_stdout do
  108. PassengerPane::Runner.run({}, %w(restart))
  109. end
  110. end
  111. end
  112. describe "Runner, interacting through YAML" do
  113. end