knife-azure unit tests for bootstrap: changed query_azure_mock for reuse in other tests

This commit is contained in:
Mukta 2013-04-22 12:30:21 +05:30
Родитель fe080b7e61
Коммит 5d425032fd
3 изменённых файлов: 17 добавлений и 60 удалений

2
.rspec Normal file
Просмотреть файл

@ -0,0 +1,2 @@
--color
--format progress

Просмотреть файл

@ -4,12 +4,14 @@
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../unit/query_azure_mock')
require 'chef/knife/bootstrap'
require 'chef/knife/bootstrap_windows_winrm'
require 'chef/knife/bootstrap_windows_ssh'
describe Chef::Knife::AzureServerCreate do
include AzureSpecHelper
include QueryAzureMock
before do
@server_instance = Chef::Knife::AzureServerCreate.new
@ -170,62 +172,4 @@ describe "for bootstrap protocol ssh:" do
end
def stub_query_azure(conn)
conn.stub(:query_azure) do |name, verb, body|
Chef::Log.info 'calling web service:' + name
if verb == 'get' || verb == nil
retval = ''
if name == 'images'
retval = Nokogiri::XML readFile('list_images.xml')
elsif name == 'disks'
retval = Nokogiri::XML readFile('list_disks.xml')
elsif name == 'hostedservices'
retval = Nokogiri::XML readFile('list_hosts.xml')
elsif name == 'hostedservices/service001/deploymentslots/Production'
retval = Nokogiri::XML readFile('list_deployments_for_service001.xml')
elsif name == 'hostedservices/service002/deploymentslots/Production'
retval = Nokogiri::XML readFile('list_deployments_for_service002.xml')
elsif name == 'hostedservices/service003/deploymentslots/Production'
retval = Nokogiri::XML readFile('list_deployments_for_service003.xml')
elsif name == 'storageservices'
retval = Nokogiri::XML readFile('list_storageaccounts.xml')
else
Chef::Log.warn 'unknown get value:' + name
end
@getname = name
@getverb = verb
@getbody = body
elsif verb == 'post'
if name == 'hostedservices'
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
elsif name == 'hostedservices/unknown_yet/deployments'
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
elsif name == 'hostedservices/service001/deployments/deployment001/roles'
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
elsif name =~ /hostedservices\/vm01.*\/deployments/
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
else
Chef::Log.warn 'unknown post value:' + name
end
@postname = name
@postverb = verb
@postbody = body
elsif verb == 'delete'
@deletename = name
@deleteverb = verb
@deletebody = body
@deletecount += 1
else
Chef::Log.warn 'unknown verb:' + verb
end
retval
end
end
end

Просмотреть файл

@ -1,6 +1,15 @@
module QueryAzureMock
def setup_query_azure_mock
create_connection
stub_query_azure (@connection)
end
def create_connection
@connection = Azure::Connection.new(TEST_PARAMS)
end
def stub_query_azure (connection)
@getname = ''
@getverb = ''
@getbody = ''
@ -15,8 +24,7 @@ module QueryAzureMock
@deletecount = 0
@receivedXML = Nokogiri::XML ''
@connection = Azure::Connection.new(TEST_PARAMS)
@connection.stub(:query_azure) do |name, verb, body|
connection.stub(:query_azure) do |name, verb, body|
Chef::Log.info 'calling web service:' + name
if verb == 'get' || verb == nil
retval = ''
@ -50,6 +58,9 @@ module QueryAzureMock
elsif name == 'hostedservices/service001/deployments/deployment001/roles'
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
elsif name =~ /hostedservices\/vm01.*\/deployments/
retval = Nokogiri::XML readFile('post_success.xml')
@receivedXML = body
else
Chef::Log.warn 'unknown post value:' + name
end