1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

update xml parsing to be more consistent, return nil instead of ''

This commit is contained in:
geemus 2010-05-05 13:39:41 -07:00
parent ea5f328110
commit eaff8be181
30 changed files with 47 additions and 41 deletions

View file

@ -20,7 +20,7 @@ class Parser < Nokogiri::XML::SAX::Document
end
def start_element(name, attrs = [])
@value = ''
@value = nil
end
def end_element(name)

View file

@ -11,10 +11,10 @@ module Fog
end
def start_element(name, attrs = [])
super
if name == 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)

View file

@ -13,6 +13,7 @@ module Fog
end
def start_element(name, attrs = [])
super
case name
when 'blockDeviceMapping'
@in_block_device_mapping = true
@ -21,7 +22,6 @@ module Fog
when 'instancesSet'
@in_instances_set = true
end
@value = ''
end
def end_element(name)

View file

@ -14,6 +14,7 @@ module Fog
end
def start_element(name, attrs = [])
super
if name == 'groups'
@in_groups = true
elsif name == 'ipPermissions'
@ -21,7 +22,6 @@ module Fog
elsif name == 'ipRanges'
@in_ip_ranges = true
end
@value = ''
end
def end_element(name)

View file

@ -13,10 +13,10 @@ module Fog
end
def start_element(name, attrs = [])
super
if name == 'attachmentSet'
@in_attachment_set = true
end
@value = ''
end
def end_element(name)

View file

@ -14,7 +14,9 @@ module Fog
when 'instanceId', 'requestId'
@response[name] = @value
when 'output'
@response[name] = Base64.decode64(@value)
if @value
@response[name] = Base64.decode64(@value)
end
when 'timestamp'
@response[name] = Time.parse(@value)
end

View file

@ -12,6 +12,7 @@ module Fog
end
def start_element(name, attrs = [])
super
case name
when 'blockDeviceMapping'
@in_block_device_mapping = true
@ -20,7 +21,6 @@ module Fog
when 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)

View file

@ -11,12 +11,12 @@ module Fog
end
def start_element(name, attrs = [])
super
if name == 'previousState'
@in_previous_state = true
elsif name == 'currentState'
@in_current_state = true
end
@value = ''
end
def end_element(name)

View file

@ -13,6 +13,7 @@ module Fog
end
def start_element(name, attrs = [])
super
case name
when 'ListenerDescriptions'
@in_listeners = true
@ -29,7 +30,6 @@ module Fog
when 'AppCookieStickinessPolicies'
@in_app_cookies = true
end
@value = ''
end
def end_element(name)

View file

@ -13,11 +13,12 @@ module Fog
end
def characters(string)
@value ||= ''
@value << string.strip
end
def start_element(name, attrs = [])
@value = ''
@value = nil
end
end

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'CatalogItem'
catalog_item = {}

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Entity'
until attributes.empty?

View file

@ -12,7 +12,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'PublicIPAddress'
@in_public_ip_address = true

View file

@ -10,10 +10,6 @@ module Fog
@response = { 'IpAddresses' => [] }
end
def start_element(name,attributes=[])
@value = ''
end
def end_element(name)
case name
when 'Name', 'Status', 'Server'

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
if name == 'Org'
organization = {}
until attributes.empty?

View file

@ -11,7 +11,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Owner', 'Result'
data = {}

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}

View file

@ -26,7 +26,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Cpu'
@in_cpu = true

View file

@ -11,7 +11,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}

View file

@ -11,7 +11,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Href'
data = {}

View file

@ -12,7 +12,7 @@ module Fog
end
def start_element(name,attributes=[])
@value = ''
super
case name
when "Network"
until attributes.empty?

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Owner', 'Result'
data = {}

View file

@ -10,7 +10,7 @@ module Fog
end
def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}

View file

@ -15,7 +15,7 @@ describe 'EC2.create_snapshot' do
it "should return proper attributes" do
actual = AWS[:ec2].create_snapshot(@volume_id)
actual.body['progress'].should be_a(String)
actual.body['progress'].should be_nil
@snapshot_id = actual.body['snapshotId']
actual.body['snapshotId'].should be_a(String)
actual.body['startTime'].should be_a(Time)

View file

@ -13,7 +13,7 @@ describe 'EC2.create_volume' do
actual.body['createTime'].should be_a(Time)
actual.body['requestId'].should be_a(String)
actual.body['size'].should == 1
actual.body['snapshotId'].should == ''
actual.body['snapshotId'].should be_nil
actual.body['status'].should be_a(String)
actual.body['volumeId'].should be_a(String)
@volume_id = actual.body['volumeId']

View file

@ -7,6 +7,7 @@ describe 'EC2.describe_instances' do
run_instances = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body
@instance_id = run_instances['instancesSet'].first['instanceId']
@reservation_id = run_instances['reservationId']
Fog.wait_for { AWS[:ec2].servers.get(@instance_id) }
AWS[:ec2].servers.get(@instance_id).wait_for { ready? }
end
@ -45,7 +46,9 @@ describe 'EC2.describe_instances' do
instance['productCodes'].should be_an(Array)
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
instance['ramdiskId'].should be_a(String)
instance['reason'].should be_a(String)
if instance['reason']
instance['reason'].should be_a(String)
end
# instance['rootDeviceName'].should be_a(String)
instance['rootDeviceType'].should be_a(String)
end
@ -81,7 +84,9 @@ describe 'EC2.describe_instances' do
instance['productCodes'].should be_an(Array)
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
instance['ramdiskId'].should be_a(String)
instance['reason'].should be_a(String)
if instance['reason']
instance['reason'].should be_a(String)
end
# instance['rootDeviceName'].should be_a(String)
instance['rootDeviceType'].should be_a(String)
end

View file

@ -18,7 +18,7 @@ describe 'EC2.describe_volumes' do
volume['availabilityZone'].should be_a(String)
volume['createTime'].should be_a(Time)
volume['size'].should == 1
volume['snapshotId'].should == ''
volume['snapshotId'].should be_nil
volume['status'].should be_a(String)
volume['volumeId'].should == @volume_id
volume['attachmentSet'].should == []
@ -31,7 +31,7 @@ describe 'EC2.describe_volumes' do
volume['availabilityZone'].should be_a(String)
volume['createTime'].should be_a(Time)
volume['size'].should == 1
volume['snapshotId'].should == ''
volume['snapshotId'].should be_nil
volume['status'].should be_a(String)
volume['volumeId'].should == @volume_id
volume['attachmentSet'].should == []

View file

@ -13,11 +13,13 @@ describe 'EC2.get_console_output' do
end
it "should return proper attributes" do
actual = AWS[:ec2].get_console_output(@instance_id)
actual.body['instanceId'].should be_a(String)
actual.body['output'].should be_a(String)
actual.body['requestId'].should be_a(String)
actual.body['timestamp'].should be_a(Time)
actual = AWS[:ec2].get_console_output(@instance_id).body
actual['instanceId'].should be_a(String)
if actual['output']
actual['output'].should be_a(String)
end
actual['requestId'].should be_a(String)
actual['timestamp'].should be_a(Time)
end
end

View file

@ -18,7 +18,7 @@ describe 'EC2.run_instances' do
instance['amiLaunchIndex'].should be_a(Integer)
# instance['architecture'].should be_a(String)
instance['blockDeviceMapping'].should be_an(Array)
instance['dnsName'].should be_a(String)
instance['dnsName'].should be_nil
instance['imageId'].should be_a(String)
instance['instanceId'].should be_a(String)
instance['instanceState'].should be_an(Hash)
@ -33,10 +33,10 @@ describe 'EC2.run_instances' do
[false, true].should include(instance['monitoring']['state'])
instance['placement'].should be_a(Hash)
instance['placement']['availabilityZone'].should be_a(String)
instance['privateDnsName'].should be_a(String)
instance['privateDnsName'].should be_nil
# instance['privateIpAddress'].should be_a(String)
instance['ramdiskId'].should be_a(String)
instance['reason'].should be_a(String)
instance['reason'].should be_nil
actual.body['ownerId'].should be_a(String)
actual.body['requestId'].should be_a(String)
actual.body['reservationId'].should be_a(String)