PageRenderTime 24ms CodeModel.GetById 2ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

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