Skip to content

Commit

Permalink
update xml parsing to be more consistent, return nil instead of ''
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed May 5, 2010
1 parent ea5f328 commit eaff8be
Show file tree
Hide file tree
Showing 30 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion benchs/parse_vs_push.rb
Expand Up @@ -20,7 +20,7 @@ def characters(string)
end

def start_element(name, attrs = [])
@value = ''
@value = nil
end

def end_element(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/describe_images.rb
Expand Up @@ -11,10 +11,10 @@ def reset
end

def start_element(name, attrs = [])
super
if name == 'productCodes'
@in_product_codes = true
end
@value = ''
end

def end_element(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/describe_instances.rb
Expand Up @@ -13,6 +13,7 @@ def reset
end

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

def end_element(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/describe_security_groups.rb
Expand Up @@ -14,14 +14,14 @@ def reset
end

def start_element(name, attrs = [])
super
if name == 'groups'
@in_groups = true
elsif name == 'ipPermissions'
@in_ip_permissions = true
elsif name == 'ipRanges'
@in_ip_ranges = true
end
@value = ''
end

def end_element(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/describe_volumes.rb
Expand Up @@ -13,10 +13,10 @@ def reset
end

def start_element(name, attrs = [])
super
if name == 'attachmentSet'
@in_attachment_set = true
end
@value = ''
end

def end_element(name)
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aws/parsers/ec2/get_console_output.rb
Expand Up @@ -14,7 +14,9 @@ def end_element(name)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/run_instances.rb
Expand Up @@ -12,6 +12,7 @@ def reset
end

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

def end_element(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/ec2/terminate_instances.rb
Expand Up @@ -11,12 +11,12 @@ def reset
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/elb/describe_load_balancers.rb
Expand Up @@ -13,6 +13,7 @@ def reset
end

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

def end_element(name)
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/parser.rb
Expand Up @@ -13,11 +13,12 @@ def reset
end

def characters(string)
@value ||= ''
@value << string.strip
end

def start_element(name, attrs = [])
@value = ''
@value = nil
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_catalog.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'CatalogItem'
catalog_item = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_catalog_item.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Entity'
until attributes.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_internet_services.rb
Expand Up @@ -12,7 +12,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'PublicIPAddress'
@in_public_ip_address = true
Expand Down
4 changes: 0 additions & 4 deletions lib/fog/terremark/parsers/shared/get_network_ips.rb
Expand Up @@ -10,10 +10,6 @@ def reset
@response = { 'IpAddresses' => [] }
end

def start_element(name,attributes=[])
@value = ''
end

def end_element(name)
case name
when 'Name', 'Status', 'Server'
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_organization.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_organizations.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
if name == 'Org'
organization = {}
until attributes.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_tasks_list.rb
Expand Up @@ -11,7 +11,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Owner', 'Result'
data = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_vapp_template.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/get_vdc.rb
Expand Up @@ -26,7 +26,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Cpu'
@in_cpu = true
Expand Down
Expand Up @@ -11,7 +11,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/internet_service.rb
Expand Up @@ -11,7 +11,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Href'
data = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/network.rb
Expand Up @@ -12,7 +12,7 @@ def reset
end

def start_element(name,attributes=[])
@value = ''
super
case name
when "Network"
until attributes.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/task.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Owner', 'Result'
data = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/terremark/parsers/shared/vapp.rb
Expand Up @@ -10,7 +10,7 @@ def reset
end

def start_element(name, attributes)
@value = ''
super
case name
when 'Link'
link = {}
Expand Down
2 changes: 1 addition & 1 deletion spec/aws/requests/ec2/create_snapshot_spec.rb
Expand Up @@ -15,7 +15,7 @@

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)
Expand Down
2 changes: 1 addition & 1 deletion spec/aws/requests/ec2/create_volume_spec.rb
Expand Up @@ -13,7 +13,7 @@
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']
Expand Down
9 changes: 7 additions & 2 deletions spec/aws/requests/ec2/describe_instances_spec.rb
Expand Up @@ -7,6 +7,7 @@
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

Expand Down Expand Up @@ -45,7 +46,9 @@
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
Expand Down Expand Up @@ -81,7 +84,9 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/aws/requests/ec2/describe_volumes_spec.rb
Expand Up @@ -18,7 +18,7 @@
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 == []
Expand All @@ -31,7 +31,7 @@
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 == []
Expand Down
12 changes: 7 additions & 5 deletions spec/aws/requests/ec2/get_console_output_spec.rb
Expand Up @@ -13,11 +13,13 @@
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
Expand Down
6 changes: 3 additions & 3 deletions spec/aws/requests/ec2/run_instances_spec.rb
Expand Up @@ -18,7 +18,7 @@
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)
Expand All @@ -33,10 +33,10 @@
[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)
Expand Down

0 comments on commit eaff8be

Please sign in to comment.