forked from openshift/rhc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests, reorganize wizard slightly
- Loading branch information
1 parent
5f682ae
commit b39461e
Showing
12 changed files
with
210 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ | |
|
||
describe RHC::Commands::App do | ||
let!(:rest_client){ MockRestClient.new } | ||
before(:each) do | ||
let!(:config){ user_config } | ||
before{ RHC::Config.stub(:home_dir).and_return('/home/mock_user') } | ||
before do | ||
FakeFS.activate! | ||
FakeFS::FileSystem.clear | ||
user_config | ||
RHC::Helpers.send(:remove_const, :MAX_RETRIES) rescue nil | ||
RHC::Helpers.const_set(:MAX_RETRIES, 3) | ||
@instance = RHC::Commands::App.new | ||
|
@@ -38,7 +39,7 @@ | |
end | ||
|
||
context 'app' do | ||
let(:arguments) { ['app', '--noprompt', '--config', 'test.conf', '-l', '[email protected]', '-p', 'password'] } | ||
let(:arguments) { ['app'] } | ||
it { run_output.should match('Usage:') } | ||
end | ||
end | ||
|
@@ -49,11 +50,44 @@ | |
it("shows number of started"){ subject.send(:gear_group_state, ['started', 'idle']).should == '1/2 started' } | ||
end | ||
|
||
describe 'app create' do | ||
before(:each) do | ||
domain = rest_client.add_domain("mockdomain") | ||
describe '#check_domain!' do | ||
let(:rest_client){ stub('RestClient') } | ||
let(:domain){ stub('Domain', :id => 'test') } | ||
before{ subject.stub(:rest_client).and_return(rest_client) } | ||
let(:interactive){ false } | ||
before{ subject.stub(:interactive?).and_return(interactive) } | ||
|
||
context "when no options are provided and there is one domain" do | ||
before{ rest_client.should_receive(:domains).twice.and_return([domain]) } | ||
it("should load the first domain"){ subject.send(:check_domain!).should == domain } | ||
after{ subject.send(:options).namespace.should == domain.id } | ||
end | ||
|
||
context "when no options are provided and there are no domains" do | ||
before{ rest_client.should_receive(:domains).and_return([]) } | ||
it("should load the first domain"){ expect{ subject.send(:check_domain!) }.to raise_error(RHC::Rest::DomainNotFoundException) } | ||
after{ subject.send(:options).namespace.should be_nil } | ||
end | ||
|
||
context "when valid namespace is provided" do | ||
before{ subject.send(:options)[:namespace] = 'test' } | ||
before{ rest_client.should_receive(:find_domain).with('test').and_return(domain) } | ||
it("should load the requested domain"){ subject.send(:check_domain!).should == domain } | ||
after{ subject.send(:options).namespace.should == 'test' } | ||
end | ||
|
||
context "when interactive and no domains" do | ||
let(:interactive){ true } | ||
before{ rest_client.should_receive(:domains).twice.and_return([]) } | ||
before{ RHC::DomainWizard.should_receive(:new).and_return(stub(:run => true)) } | ||
it("should raise if the wizard doesn't set the option"){ expect{ subject.send(:check_domain!) }.to raise_error(RHC::Rest::DomainNotFoundException) } | ||
after{ subject.send(:options).namespace.should be_nil } | ||
end | ||
end | ||
|
||
describe 'app create' do | ||
before{ rest_client.add_domain("mockdomain") } | ||
|
||
context "when we ask for help with the alias" do | ||
before{ FakeFS.deactivate! } | ||
context do | ||
|
@@ -66,6 +100,68 @@ | |
end | ||
end | ||
|
||
context "when run with no arguments" do | ||
before{ FakeFS.deactivate! } | ||
let(:arguments){ ['create-app'] } | ||
it{ run_output.should match "Usage: rhc app-create <name>" } | ||
it{ run_output.should match "When creating an application, you must provide a name and a cartridge from the list below:" } | ||
it{ run_output.should match "mock_standalone_cart-1" } | ||
it{ run_output.should match "Please specify the name of the application" } | ||
end | ||
|
||
context "when dealing with config" do | ||
subject{ described_class.new(Commander::Command::Options.new(options)) } | ||
let(:wizard){ s = stub('Wizard'); RHC::EmbeddedWizard.should_receive(:new).and_return(s); s } | ||
let(:options){ nil } | ||
let(:interactive){ true } | ||
before{ subject.should_receive(:interactive?).at_least(1).times.and_return(interactive) } | ||
before{ subject.stub(:check_sshkeys!) } | ||
|
||
it("should run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to call(:run).on(wizard).and_stop } | ||
|
||
context "when has config" do | ||
let(:options){ {:server => 'test', :rhlogin => 'foo'} } | ||
before{ subject.send(:config).should_receive(:has_local_config?).and_return(true) } | ||
it("should not run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to not_call(:new).on(RHC::EmbeddedWizard) } | ||
end | ||
|
||
context "when has no config" do | ||
before{ subject.send(:config).should_receive(:has_local_config?).and_return(false) } | ||
it("should run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to call(:new).on(RHC::EmbeddedWizard).and_stop } | ||
end | ||
|
||
context "when not interactive" do | ||
let(:interactive){ false } | ||
it("should not run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to not_call(:new).on(RHC::EmbeddedWizard) } | ||
end | ||
end | ||
|
||
context "when dealing with ssh keys" do | ||
subject{ described_class.new(options) } | ||
let(:wizard){ s = stub('Wizard'); RHC::SSHWizard.should_receive(:new).and_return(s); s } | ||
let(:options){ Commander::Command::Options.new(:server => 'foo.com', :rhlogin => 'test') } | ||
let(:interactive){ true } | ||
before{ subject.should_receive(:interactive?).at_least(1).times.and_return(interactive) } | ||
before{ subject.should_receive(:check_config!) } | ||
|
||
it("should run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to call(:run).on(wizard).and_stop } | ||
|
||
context "when not interactive" do | ||
let(:interactive){ false } | ||
it("should not run the wizard"){ expect{ subject.create('name', ['mock_standalone_cart-1']) }.to not_call(:new).on(RHC::SSHWizard) } | ||
end | ||
end | ||
|
||
context "when in full interactive mode with no keys, domain, or config" do | ||
let!(:config){ base_config } | ||
before{ RHC::Config.any_instance.stub(:has_local_config?).and_return(false) } | ||
before{ described_class.any_instance.stub(:interactive?).and_return(true) } | ||
before{ rest_client.domains.clear } | ||
let(:arguments) { ['app', 'create', 'app1', 'mock_standalone_cart-1'] } | ||
# skips login stage and insecure check because of mock rest client, doesn't check keys | ||
it { run_output(['mydomain', 'y', 'mykey']).should match(/This wizard.*Checking your namespace.*Your domain name 'mydomain' has been successfully created.*Creating application.*Your public SSH key.*Uploading key 'mykey' from.*Downloading the application.*Success/m) } | ||
end | ||
|
||
context 'when run without a cart' do | ||
before{ FakeFS.deactivate! } | ||
let(:arguments) { ['app', 'create', 'app1', '--noprompt', '--timeout', '10', '--config', 'test.conf', '-l', '[email protected]', '-p', 'password'] } | ||
|
@@ -273,7 +369,7 @@ | |
before(:each) do | ||
@domain = rest_client.add_domain("mockdomain") | ||
@instance.stub(:git_clone_application) { raise RHC::GitException } | ||
@instance.should_not_receive(:check_sshkeys!) | ||
@instance.stub(:check_sshkeys!) | ||
end | ||
|
||
context 'when run with error in git clone' do | ||
|
Oops, something went wrong.