---
spec/command/hwp_create_command_spec.rb | 46 +++++++++++++++
spec/command/hwp_delete_command_spec.rb | 51 ++++++++++++++++
spec/command/hwp_list_command_spec.rb | 37 ++++++++++++
spec/command/hwp_parser_spec.rb | 96 +++++++++++++++++++++++++++++++
4 files changed, 230 insertions(+), 0 deletions(-)
create mode 100644 spec/command/hwp_create_command_spec.rb
create mode 100644 spec/command/hwp_delete_command_spec.rb
create mode 100644 spec/command/hwp_list_command_spec.rb
create mode 100644 spec/command/hwp_parser_spec.rb
diff --git a/spec/command/hwp_create_command_spec.rb
b/spec/command/hwp_create_command_spec.rb
new file mode 100644
index 0000000..f888502
--- /dev/null
+++ b/spec/command/hwp_create_command_spec.rb
@@ -0,0 +1,46 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe HwpCreateCommand do
+ context "Sucessful Create" do
+ it "should create a hwp with given params" do
+ @options = {:name => 'new_hwp', :memory => '512', :cpu
=> '2', :storage => '500', :arch => 'i386'}
+ VCR.use_cassette('command/create_command/create_hwp') do
+ cc = HwpCreateCommand.new(@options)
+ begin
+ cc.run
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Name")
+ $stdout.string.should include("Memory")
+ $stdout.string.should include("Storage")
+ $stdout.string.should include("CPU")
+ $stdout.string.should include("architecture")
+
+ $stdout.string.should include("new_hwp")
+ $stdout.string.should include("512")
+ $stdout.string.should include("500")
+ $stdout.string.should include("2")
+ $stdout.string.should include("i386")
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/command/hwp_delete_command_spec.rb
b/spec/command/hwp_delete_command_spec.rb
new file mode 100644
index 0000000..d95645c
--- /dev/null
+++ b/spec/command/hwp_delete_command_spec.rb
@@ -0,0 +1,51 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe HwpDeleteCommand do
+ context "Sucessful Delete" do
+ it "should delete a hwp of a given id" do
+ @options = {:id => 10}
+ VCR.use_cassette('command/delete_command/delete_hwp') do
+ dc = HwpDeleteCommand.new(@options)
+ begin
+ dc.run
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Hardware profile: 10 Deleted
Successfully")
+ end
+ end
+ end
+
+ context "Delete Failed Not Found" do
+ it "should display an appropriate message when the given hwp is not
found" do
+ VCR.use_cassette('command/delete_command/delete_hwp_not_found') do
+ @options = {:id => "1234"}
+ dc = HwpDeleteCommand.new(@options)
+ begin
+ dc.run
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ $stdout.string.should include("Couldn't find HardwareProfile with
ID=1234")
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/command/hwp_list_command_spec.rb
b/spec/command/hwp_list_command_spec.rb
new file mode 100644
index 0000000..4dc911f
--- /dev/null
+++ b/spec/command/hwp_list_command_spec.rb
@@ -0,0 +1,37 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe HwpListCommand do
+ it "should list all hwps" do
+ VCR.use_cassette('command/list_command/list_all_hwps') do
+ lc = HwpListCommand.new
+ begin
+ lc.run
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ headers = ["ID", "Name", "Memory",
"Storage", "CPU", "architecture"]
+ content = ["1", "hwp1", "512", "nil",
"1", "x86_64"]
+ (headers + content).each do |expected_text|
+ $stdout.string.should include(expected_text)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/command/hwp_parser_spec.rb b/spec/command/hwp_parser_spec.rb
new file mode 100644
index 0000000..e9d9550
--- /dev/null
+++ b/spec/command/hwp_parser_spec.rb
@@ -0,0 +1,96 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe HwpParser do
+ it "should parse the specified hwp command" do
+ VCR.use_cassette('command/list_command/list_all_hwps') do
+ begin
+ hwp_parser = HwpParser.new(%w(list))
+ hwp_parser.process
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ hwp_parser.command.should == 'list'
+ end
+ end
+
+ it "should exit gracefully when a required option is not provided" do
+ begin
+ silence_stream(STDOUT) do
+ hwp_parser = HwpParser.new(%w(create))
+ hwp_parser.process
+ hwp_parser.should_receive(:exit).with(1)
+ end
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ end
+
+ it "should notify the user of an invalid command" do
+ hwp_parser = HwpParser.new(%w(sparkle))
+ hwp_parser.should_receive(:exit).with(1)
+ silence_stream(STDOUT) do
+ hwp_parser.process
+ end
+ end
+
+ it "should exit gracefully with bad params" do
+ begin
+ silence_stream(STDOUT) do
+ hwp_parser = HwpParser.new(%w(create --fred))
+ hwp_parser.process
+ hwp_parser.should_receive(:exit).with(1)
+ end
+ rescue SystemExit => e
+ e.status.should == 1
+ end
+ end
+
+ context "setting options hash" do
+ subject { hwp_parser }
+ let ( :parameters ) { %w{} }
+ let ( :hwp_parser ) { HwpParser.new( parameters ) }
+
+ before(:each) do
+ Aeolus::CLI::HwpParser::COMMANDS.each do |command|
+ subject.stub!( command.to_sym )
+ end
+ subject.process
+ end
+
+ context "for delete command" do
+ context "with --id " do
+ let ( :parameters ) { %w(delete --id 12345) }
+ let ( :options_hash ) { { :id => '12345' } }
+
+ its ( :options ) { should include( options_hash ) }
+ end
+ end
+
+ context "for create command" do
+ context "with --name, --memory, --cpu, --storage, --arch" do
+ let ( :parameters ) { %w(create --name hwp2 --memory 512 --cpu 2 --storage
500 --arch i386) }
+ let ( :options_hash ) { { :name => 'hwp2', :memory =>
'512', :cpu => '2', :storage => '500', :arch =>
'i386' } }
+
+ its ( :options ) { should include( options_hash ) }
+ end
+ end
+ end
+ end
+ end
+end
--
1.7.7.6