[PATCH aeolus-cli 2/2] Change and refactor tests for refactored option parser use
Martyn Taylor
mtaylor at redhat.com
Thu Dec 1 13:36:37 UTC 2011
Ack - Rebased and Pushed
Thanks
On 11/29/2011 01:51 PM, pblaho at redhat.com wrote:
> From: Petr Blaho<pblaho at redhat.com>
>
> This support mzatko's patch a11b9902b9e3dbb6f13cab9c8a2cb9f6f232edfb
>
> This is tests of solution for https://bugzilla.redhat.com/show_bug.cgi?id=754956
> ---
> spec/command/config_parser_spec.rb | 160 ++++++++++++++++++++++++++++++------
> 1 files changed, 133 insertions(+), 27 deletions(-)
>
> diff --git a/spec/command/config_parser_spec.rb b/spec/command/config_parser_spec.rb
> index f4e48ec..2175b02 100644
> --- a/spec/command/config_parser_spec.rb
> +++ b/spec/command/config_parser_spec.rb
> @@ -52,43 +52,149 @@ module Aeolus
> it "should exit gracefully with bad params" do
> begin
> silence_stream(STDOUT) do
> - ConfigParser.new(%w(delete --fred)).should_receive(:exit).with(1)
> + config_parser = ConfigParser.new(%w(delete --fred))
> + config_parser.process
> + config_parser.should_receive(:exit).with(1)
> end
> rescue SystemExit => e
> e.status.should == 1
> end
> end
>
> - it "should set options hash for valid list options" do
> - config_parser = ConfigParser.new(%w(list --builds 12345))
> - config_parser.options[:subcommand].should == :builds
> - config_parser.options[:id].should == '12345'
> - end
> + context "setting options hash" do
> + subject { config_parser }
> + let ( :parameters ) { %w{} }
> + let ( :config_parser ) { ConfigParser.new( parameters ) }
>
> - it "should set options hash for valid build options" do
> - config_parser = ConfigParser.new(%w(build --target ec2,rackspace --image 12345 --template my.tmpl))
> - config_parser.options[:target].should == ['ec2','rackspace']
> - config_parser.options[:image].should == '12345'
> - config_parser.options[:template].should == 'my.tmpl'
> - end
> + before(:each) do
> + Aeolus::CLI::ConfigParser::COMMANDS.each do |command|
> + subject.stub!( command.to_sym )
> + end
> + subject.process
> + end
>
> - it "should set options hash for valid push options" do
> - config_parser = ConfigParser.new(%w(push --provider ec2-us-east1 --id 12345))
> - config_parser.options[:provider].should == ['ec2-us-east1']
> - config_parser.options[:id].should == '12345'
> - end
> + context "for list command" do
> + context "with --images" do
> + let ( :parameters ) { %w(list --images) }
> + let ( :options_hash ) { { :subcommand => :images } }
>
> - it "should set options hash for valid delete options" do
> - config_parser = ConfigParser.new(%w(delete --build 12345))
> - config_parser.options[:build].should == '12345'
> - end
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --builds ID" do
> + let ( :parameters ) { %w(list --builds 12345) }
> + let ( :options_hash ) { { :subcommand => :builds, :id => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --targetimages ID" do
> + let ( :parameters ) { %w(list --targetimages 12345) }
> + let ( :options_hash ) { { :subcommand => :targetimages, :id => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --providerimages ID" do
> + let ( :parameters ) { %w(list --providerimages 12345) }
> + let ( :options_hash ) { { :subcommand => :providerimages, :id => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --targets" do
> + let ( :parameters ) { %w(list --targets) }
> + let ( :options_hash ) { { :subcommand => :targets } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --providers" do
> + let ( :parameters ) { %w(list --providers) }
> + let ( :options_hash ) { { :subcommand => :providers } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --accounts" do
> + let ( :parameters ) { %w(list --accounts) }
> + let ( :options_hash ) { { :subcommand => :accounts } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + end
> +
> + context "for build command" do
> + context "with --template FILE" do
> + let ( :parameters ) { %w(build --target ec2,rackspace --image 12345 --template my.tmpl) }
> + let ( :options_hash ) { { :target => ['ec2','rackspace'], :image => '12345', :template => 'my.tmpl' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --no-validation" do
> + let ( :parameters ) { %w(build --target ec2,rackspace --image 12345 --no-validation) }
> + let ( :options_hash ) { { :target => ['ec2','rackspace'], :image => '12345', :validation => false } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + end
> +
> + context "for push command" do
> + context "without other options" do
> + let ( :parameters ) { %w(push --provider ec2-us-east1 --id 12345) }
> + let ( :options_hash ) { { :provider => ['ec2-us-east1'], :id => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --build ID" do
> + let ( :parameters ) { %w(push --provider ec2-us-east1 --build 12345) }
> + let ( :options_hash ) { { :provider => ['ec2-us-east1'], :build => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --targetimage ID" do
> + let ( :parameters ) { %w(push --provider ec2-us-east1 --targetimage 12345) }
> + let ( :options_hash ) { { :provider => ['ec2-us-east1'], :targetimage => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --account NAME" do
> + let ( :parameters ) { %w(push --provider ec2-us-east1 --account 12345) }
> + let ( :options_hash ) { { :provider => ['ec2-us-east1'], :account => '12345' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + end
> +
> + context "for delete command" do
> + context "with --image ID" do
> + let ( :parameters ) { %w(delete --image 12345) }
> + let ( :options_hash ) { { :image => '12345', :subcommand => :image } }
>
> - it "should set options hash for valid import options" do
> - config_parser = ConfigParser.new(%w(import --provider ec2-us-east-1a --description /path/to/file --id ami-123456 --target ec2))
> - config_parser.options[:provider].should == ['ec2-us-east-1a']
> - config_parser.options[:target].should == ['ec2']
> - config_parser.options[:description].should == '/path/to/file'
> - config_parser.options[:id].should == 'ami-123456'
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --build ID" do
> + let ( :parameters ) { %w(delete --build 12345) }
> + let ( :options_hash ) { { :build => '12345', :subcommand => :build } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --targetimage ID" do
> + let ( :parameters ) { %w(delete --targetimage 12345) }
> + let ( :options_hash ) { { :targetimage => '12345', :subcommand => :target_image } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + context "with --providerimage ID" do
> + let ( :parameters ) { %w(delete --providerimage 12345) }
> + let ( :options_hash ) { { :providerimage => '12345', :subcommand => :provider_image } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + end
> +
> + context "for import command" do
> + context "without other options" do
> + let ( :parameters ) { %w(import --provider ec2-us-east-1a --description /path/to/file --id ami-123456 --target ec2) }
> + let ( :options_hash ) { { :provider => ['ec2-us-east-1a'], :target => ['ec2'], :description => '/path/to/file', :id => 'ami-123456' } }
> +
> + its ( :options ) { should include( options_hash ) }
> + end
> + end
> end
> end
> end
More information about the aeolus-devel
mailing list