internuity-awsum 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/Rakefile +2 -1
  2. data/lib/awsum.rb +1 -1
  3. data/lib/ec2/address.rb +118 -0
  4. data/lib/ec2/availability_zone.rb +68 -0
  5. data/lib/ec2/keypair.rb +75 -0
  6. data/lib/ec2/region.rb +96 -0
  7. data/lib/ec2/security_group.rb +175 -0
  8. data/lib/error.rb +55 -0
  9. data/lib/net_fix.rb +100 -0
  10. data/lib/requestable.rb +2 -0
  11. data/lib/s3/bucket.rb +66 -0
  12. data/lib/s3/headers.rb +24 -0
  13. data/lib/s3/object.rb +138 -0
  14. data/lib/s3/s3.rb +219 -0
  15. data/test/fixtures/ec2/addresses.xml +10 -0
  16. data/test/fixtures/ec2/allocate_address.xml +5 -0
  17. data/test/fixtures/ec2/associate_address.xml +5 -0
  18. data/test/fixtures/ec2/authorize_ip_access.xml +5 -0
  19. data/test/fixtures/ec2/authorize_owner_group_access.xml +5 -0
  20. data/test/fixtures/ec2/authorize_owner_group_access_error.xml +2 -0
  21. data/test/fixtures/ec2/availability_zones.xml +16 -0
  22. data/test/fixtures/ec2/create_key_pair.xml +29 -0
  23. data/test/fixtures/ec2/create_security_group.xml +5 -0
  24. data/test/fixtures/ec2/delete_key_pair.xml +5 -0
  25. data/test/fixtures/ec2/delete_security_group.xml +5 -0
  26. data/test/fixtures/ec2/deregister_image.xml +5 -0
  27. data/test/fixtures/ec2/disassociate_address.xml +5 -0
  28. data/test/fixtures/ec2/internal_error.xml +2 -0
  29. data/test/fixtures/ec2/invalid_amiid_error.xml +2 -0
  30. data/test/fixtures/ec2/invalid_request_error.xml +2 -0
  31. data/test/fixtures/ec2/key_pairs.xml +10 -0
  32. data/test/fixtures/ec2/regions.xml +14 -0
  33. data/test/fixtures/ec2/register_image.xml +5 -0
  34. data/test/fixtures/ec2/release_address.xml +5 -0
  35. data/test/fixtures/ec2/revoke_ip_access.xml +5 -0
  36. data/test/fixtures/ec2/revoke_owner_group_access.xml +5 -0
  37. data/test/fixtures/ec2/security_groups.xml +159 -0
  38. data/test/fixtures/ec2/unassociated_address.xml +10 -0
  39. data/test/fixtures/s3/buckets.xml +2 -0
  40. data/test/fixtures/s3/copy_failure.xml +23 -0
  41. data/test/fixtures/s3/invalid_request_signature.xml +5 -0
  42. data/test/fixtures/s3/keys.xml +2 -0
  43. data/test/units/ec2/test_addresses.rb +60 -0
  44. data/test/units/ec2/test_keypair.rb +87 -0
  45. data/test/units/ec2/test_regions.rb +33 -0
  46. data/test/units/ec2/test_security_group.rb +105 -0
  47. data/test/units/s3/test_bucket.rb +58 -0
  48. data/test/units/s3/test_object.rb +111 -0
  49. data/test/units/s3/test_s3.rb +298 -0
  50. data/test/units/test_error.rb +101 -0
  51. data/test/units/test_requestable.rb +241 -0
  52. data/test/work_out_string_to_sign.rb +7 -0
  53. metadata +132 -43
@@ -0,0 +1,87 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class KeyPairsTest < Test::Unit::TestCase
4
+ context "KeyPairParser:" do
5
+ context "Parsing the result of a call to DescribeKeyPairs" do
6
+ setup {
7
+ ec2 = Awsum::Ec2.new('abc', 'xyz')
8
+ xml = load_fixture('ec2/key_pairs')
9
+ parser = Awsum::Ec2::KeyPairParser.new(ec2)
10
+ @result = parser.parse(xml)
11
+ }
12
+
13
+ should "return an array of key pairs" do
14
+ assert @result.is_a?(Array)
15
+ assert @result[0].is_a?(Awsum::Ec2::KeyPair)
16
+ end
17
+
18
+ context ", the first key pair" do
19
+ setup {
20
+ @key_pair = @result[0]
21
+ }
22
+
23
+ should "have the correct name" do
24
+ assert_equal "gsg-keypair", @key_pair.name
25
+ end
26
+
27
+ should "have the correct fingerprint" do
28
+ assert_equal "ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab", @key_pair.fingerprint
29
+ end
30
+ end
31
+ end
32
+
33
+ context "Parsing the result of a call to CreateKeyPair" do
34
+ setup {
35
+ ec2 = Awsum::Ec2.new('abc', 'xyz')
36
+ xml = load_fixture('ec2/create_key_pair')
37
+ parser = Awsum::Ec2::KeyPairParser.new(ec2)
38
+ @result = parser.parse(xml)
39
+ }
40
+
41
+ should "return an array of key pairs" do
42
+ assert @result.is_a?(Array)
43
+ assert @result[0].is_a?(Awsum::Ec2::KeyPair)
44
+ end
45
+
46
+ context ", the first key pair" do
47
+ setup {
48
+ @key_pair = @result[0]
49
+ }
50
+
51
+ should "have the correct name" do
52
+ assert_equal "test-keypair", @key_pair.name
53
+ end
54
+
55
+ should "have the correct fingerprint" do
56
+ assert_equal "ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab:ab", @key_pair.fingerprint
57
+ end
58
+
59
+ should "have the correct material" do
60
+ assert_equal %q{-----BEGIN RSA PRIVATE KEY-----
61
+ MIIEogIBAAKCAQEAqkxIjNxLV/shvaep5Kum3N2xTV6aBbXezVA4HHE371HSq3haKTcST7QYeQha
62
+ 92AmZojAm2ojqWMw9GJaeq/Q7NvXKdMgj3mKd7zY7tdC+HmKYVkAvJ9enuuVwPFxlt+5rPpZ2jS+
63
+ kl4MWEvWh1N5U1urx5gzHq2e/k7P+dCBwFnCHsg/p1mym4j4qwEHEviaUG6SnB8Xvuggp/pxCmJg
64
+ 9Gie4cXNgbBboEyAQDRb/AmrehbBa90GOVDjDGIzB98rOcJ22FRrpLqSl2D+FQKsXWboqgbIrgKT
65
+ ven7mzb8cgDJNrWTI/MNP8p8gNTh+L7gTwPDcGfaDBiRpn9t3FiTBwIDAQABAoIBAEmuNZmUWpjX
66
+ U/LdjtkcF1bqKCMkchlUZfCI664KojvOOAruSHwakrafYhNDtS/gjtzAAC19z64i93RU9XatiQRh
67
+ 3YcADM9ms604rNcxlY0x8NhLjNEPVv4FScav8AhqBci8jJGnTmi/fjHZphjo2c5iFEGILV3xmp/G
68
+ 857PQsQ4nOAzoV7fQPYow4XiO/xhGh8p8o2Z9Og3GdbEGH1v/051g3O1eU7PFyQaxmOGNYmklMuM
69
+ V/8l/LK+OKR0f9KgqcgDSlEbidqsmWM0a1/t7+I5W/mgXSZl5U4HN680DKbkzoX0kgoPN7XMbcSX
70
+ sHNguqDfrvkBUQu1vEaXebWfpekCgYEA0qVbcFGxKniyYxmvtSrbb5bpEnh6zRCGXgSU4fX41i8P
71
+ Xg15R7FnwGO5nuRXqGW6CSgfbA7YAVEQHunUOB0XWuJWgn6gsqvnCZvyfRnqyMJJjRhvuaUMTn/5
72
+ ikcayflqPFHvv5Z+pB3pWNaTD6lM5imdF1In9RBYL4q5Vpt9gl0CgYEAzvb6cS6Yi0PkxU3OOEmg
73
+ 98QcdTEd1hrk3r6uXI1TOeiUPIw+dyGCKa9OqpcFDs+0FskFs6RzztRh2gpwQZTH3UOYPqsjsWd+
74
+ AjL3jv+vmpU1OhnA0SpkyiiZtaSAV2N+Xlq8orG6fbnYFCdzHbufLFaoOpbGptmLfrwMSvnhXLMC
75
+ gYBxRsEcbqHycAOmLUsDBvAIW0QtTaLkIe3QI3CY7viI3bfK4T4GIs3jdP1+B9dn1IStpej36Cea
76
+ 1afwp9ga8PH9Stgwxr3ON4k/7qABTG2o1mpNOQXj9HDgygs8pC4wzTKnC3z9L4Yc5YT15DYjZuzW
77
+ nSxAPUsFi2uQ7W3ruCRPdQKBgGslsCiyb+UBpEmFa3L2o3BCRl1hrUmwKLcszsY5oFHFmCD0lk5E
78
+ ucds6/QjNUoiu+Bj+CC1zgLRL0ubxdwd848YtJQVM+hfZPwseL++naIRBzpqJMnlAcMrW9CPNqaH
79
+ at/cZ/ZuvtbiRPzCI7XL8a8ZugSDFJtC2xYkstSKI2NDAoGAIiwUwKRMJyB9IRXhMfpf6vsEza2t
80
+ urHVUdJUyIwvPJSh2PfkumwrPuk+P+8v6jJjJ0hsqOS+TLQwWclIGwGey/PMNRYqQDqnSUofNmza
81
+ XtGGfWTOD3AdDEH39RTd3Zmfirrjm1YsY/Nb54X+V5TN2uvm/yJBIbb4aLvfG74Jmoc=
82
+ -----END RSA PRIVATE KEY-----}, @key_pair.material
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class RegionsTest < Test::Unit::TestCase
4
+ context "RegionParser:" do
5
+ context "Parsing the result of a call to DescribeRegions" do
6
+ setup {
7
+ ec2 = Awsum::Ec2.new('abc', 'xyz')
8
+ xml = load_fixture('ec2/regions')
9
+ parser = Awsum::Ec2::RegionParser.new(ec2)
10
+ @result = parser.parse(xml)
11
+ }
12
+
13
+ should "return an array of regions" do
14
+ assert @result.is_a?(Array)
15
+ assert @result[0].is_a?(Awsum::Ec2::Region)
16
+ end
17
+
18
+ context ", the first region" do
19
+ setup {
20
+ @region = @result[0]
21
+ }
22
+
23
+ should "have the correct name" do
24
+ assert_equal "eu-west-1", @region.name
25
+ end
26
+
27
+ should "have the correct end point" do
28
+ assert_equal 'eu-west-1.ec2.amazonaws.com', @region.end_point
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class SecurityGroupsTest < Test::Unit::TestCase
4
+ context "SecurityGroupParser:" do
5
+ context "Parsing the result of a call to DescribeSecurityGroups" do
6
+ setup {
7
+ ec2 = Awsum::Ec2.new('abc', 'xyz')
8
+ xml = load_fixture('ec2/security_groups')
9
+ parser = Awsum::Ec2::SecurityGroupParser.new(ec2)
10
+ @result = parser.parse(xml)
11
+ }
12
+
13
+ should "return an array of security_groups" do
14
+ assert @result.is_a?(Array)
15
+ assert @result[0].is_a?(Awsum::Ec2::SecurityGroup)
16
+ end
17
+
18
+ context ", the first security_group" do
19
+ setup {
20
+ @security_group = @result[0]
21
+ }
22
+
23
+ should "have the correct name" do
24
+ assert_equal "default", @security_group.name
25
+ end
26
+
27
+ should "have the correct description" do
28
+ assert_equal "default group", @security_group.description
29
+ end
30
+
31
+ should "have the correct owner id" do
32
+ assert_equal "111111111111", @security_group.owner_id
33
+ end
34
+
35
+ should "have 3 group permissions" do
36
+ assert_equal 3, @security_group.group_permissions.size
37
+ end
38
+
39
+ should "have SecurityGroup::GroupPermission in the group_permissions array" do
40
+ @security_group.group_permissions.each do |p|
41
+ assert_equal Awsum::Ec2::SecurityGroup::GroupPermission, p.class
42
+ end
43
+ end
44
+
45
+ should "have 4 ip permissions" do
46
+ assert_equal 4, @security_group.ip_permissions.size
47
+ end
48
+
49
+ should "have SecurityGroup::IpPermission in the ip_permissions array" do
50
+ @security_group.ip_permissions.each do |p|
51
+ assert_equal Awsum::Ec2::SecurityGroup::IpPermission, p.class
52
+ end
53
+ end
54
+
55
+ context ", in the first group permission" do
56
+ setup {
57
+ @group_permission = @security_group.group_permissions[0]
58
+ }
59
+
60
+ should "have protocol of tcp" do
61
+ assert_equal 'tcp', @group_permission.protocol
62
+ end
63
+
64
+ should "have from port of 0" do
65
+ assert_equal 0, @group_permission.from_port
66
+ end
67
+
68
+ should "have to port of 65535" do
69
+ assert_equal 65535, @group_permission.to_port
70
+ end
71
+
72
+ should "have group of default" do
73
+ assert_equal 'default', @group_permission.group
74
+ end
75
+
76
+ should "have owner id of 111111111111" do
77
+ assert_equal '111111111111', @group_permission.user_id
78
+ end
79
+ end
80
+
81
+ context ", in the first ip permission" do
82
+ setup {
83
+ @ip_permission = @security_group.ip_permissions[0]
84
+ }
85
+
86
+ should "have protocol of tcp" do
87
+ assert_equal 'tcp', @ip_permission.protocol
88
+ end
89
+
90
+ should "have from port of 22" do
91
+ assert_equal 22, @ip_permission.from_port
92
+ end
93
+
94
+ should "have to port of 22" do
95
+ assert_equal 22, @ip_permission.to_port
96
+ end
97
+
98
+ should "have ip of 0.0.0.0/0" do
99
+ assert_equal '0.0.0.0/0', @ip_permission.ip
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class BucketsTest < Test::Unit::TestCase
4
+ context "BucketParser:" do
5
+ context "Parsing the result of GET" do
6
+ setup {
7
+ s3 = Awsum::S3.new('abc', 'xyz')
8
+ xml = load_fixture('s3/buckets')
9
+ parser = Awsum::S3::BucketParser.new(s3)
10
+ @result = parser.parse(xml)
11
+ }
12
+
13
+ should "return an array of buckets" do
14
+ assert @result.is_a?(Array)
15
+ assert @result[0].is_a?(Awsum::S3::Bucket)
16
+ end
17
+
18
+ context ", the first bucket" do
19
+ setup {
20
+ @bucket = @result[0]
21
+ }
22
+
23
+ should "have the correct name" do
24
+ assert_equal "test-bucket", @bucket.name
25
+ end
26
+
27
+ should "have the correct creation date" do
28
+ assert_equal Time.parse("2008-12-04T16:08:03.000Z"), @bucket.creation_date
29
+ end
30
+ end
31
+
32
+ context ", the second bucket" do
33
+ setup {
34
+ @bucket = @result[1]
35
+ }
36
+
37
+ should "have the correct name" do
38
+ assert_equal "another-test-bucket", @bucket.name
39
+ end
40
+
41
+ should "have the correct creation date" do
42
+ assert_equal Time.parse("2009-01-02T08:25:27.000Z"), @bucket.creation_date
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context "Bucket: " do
49
+ setup {
50
+ @s3 = Awsum::S3.new('abc', 'xyz')
51
+ }
52
+
53
+ should "be able to create a bucket without calling the S3 API" do
54
+ bucket = @s3.bucket('test-bucket')
55
+ assert_equal 'test-bucket', bucket.name
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class ObjectsTest < Test::Unit::TestCase
4
+ context "ObjectParser:" do
5
+ context "Parsing the result of GET" do
6
+ setup {
7
+ s3 = Awsum::S3.new('abc', 'xyz')
8
+ xml = load_fixture('s3/keys')
9
+ parser = Awsum::S3::ObjectParser.new(s3)
10
+ @result = parser.parse(xml)
11
+ }
12
+
13
+ should "return an array of objects" do
14
+ assert @result.is_a?(Array)
15
+ assert @result[0].is_a?(Awsum::S3::Object)
16
+ end
17
+
18
+ context ", the first object" do
19
+ setup {
20
+ @object = @result[0]
21
+ }
22
+
23
+ should "have the correct key" do
24
+ assert_equal "test/photo1.jpg", @object.key
25
+ end
26
+
27
+ should "have the correct last modification date" do
28
+ assert_equal Time.parse("2008-12-07T13:47:59.000Z"), @object.last_modified
29
+ end
30
+
31
+ should "have the correct etag" do
32
+ assert_equal "\"03bde534951a1c099724f569a53acb1e\"", @object.etag
33
+ end
34
+
35
+ should "have the correct size" do
36
+ assert_equal 203841, @object.size
37
+ end
38
+
39
+ should "have the correct owner id" do
40
+ assert_equal '1111111111111111111111111111111111111111111111111111111111111111', @object.owner['id']
41
+ end
42
+
43
+ should "have the correct owner name" do
44
+ assert_equal 'AAAAAA', @object.owner['name']
45
+ end
46
+
47
+ should "have the correct storage class" do
48
+ assert_equal 'STANDARD', @object.storage_class
49
+ end
50
+ end
51
+
52
+ context ", the second object" do
53
+ setup {
54
+ @object = @result[1]
55
+ }
56
+
57
+ should "have the correct key" do
58
+ assert_equal "test/photo2.jpg", @object.key
59
+ end
60
+
61
+ should "have the correct last modification date" do
62
+ assert_equal Time.parse("2008-12-07T13:48:13.000Z"), @object.last_modified
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ context "Objects: " do
69
+ setup {
70
+ @s3 = Awsum::S3.new('abc', 'xyz')
71
+ }
72
+
73
+ context "When retrieving object headers" do
74
+ setup {
75
+ response = mock('Response')
76
+ @s3.expects(:send_s3_request).returns(response)
77
+ @headers = @s3.object_headers('test-bucket', 'test-key')
78
+ }
79
+
80
+ should "be able to retrieve object headers" do
81
+ assert @headers
82
+ end
83
+
84
+ should "be of class Awsum::S3::Headers" do
85
+ assert @headers.is_a?(Awsum::S3::Headers)
86
+ end
87
+ end
88
+
89
+ context "when retrieving object data" do
90
+ should "be able to retrieve all the data" do
91
+ response = mock('Response', :body => 'test-data')
92
+ @s3.expects(:send_s3_request).yields(response)
93
+
94
+ assert_equal 'test-data', @s3.object_data('test-bucket', 'test-key')
95
+ end
96
+
97
+ should "be able to retrieve the data in chunks" do
98
+ response = mock('Response')
99
+ response.expects(:read_body).yields('test-data')
100
+ @s3.expects(:send_s3_request).yields(response)
101
+
102
+ data = ''
103
+ @s3.object_data('test-bucket', 'test-key') do |chunk|
104
+ data << chunk
105
+ end
106
+
107
+ assert_equal 'test-data', data
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,298 @@
1
+ require File.expand_path('../../helper', File.dirname(__FILE__))
2
+
3
+ class S3Test < Test::Unit::TestCase
4
+ def setup
5
+ @s3 = Awsum::S3.new('abc', 'xyz')
6
+ end
7
+
8
+ context "Buckets: " do
9
+ context "naming a bucket" do
10
+ should "not have an ip address style name" do
11
+ assert_raise ArgumentError do
12
+ @s3.create_bucket('192.168.2.1')
13
+ end
14
+ end
15
+
16
+ should "not start with punctuation" do
17
+ assert_raise ArgumentError do
18
+ @s3.create_bucket('-name')
19
+ @s3.create_bucket('.name')
20
+ @s3.create_bucket('_name')
21
+ end
22
+ end
23
+
24
+ should "not end with a dash" do
25
+ assert_raise ArgumentError do
26
+ @s3.create_bucket('name-')
27
+ end
28
+ end
29
+
30
+ should "not have a dash to the left of a period" do
31
+ assert_raise ArgumentError do
32
+ @s3.create_bucket('name-.test')
33
+ end
34
+ end
35
+
36
+ should "not have a dash to the right of a period" do
37
+ assert_raise ArgumentError do
38
+ @s3.create_bucket('name.-test')
39
+ end
40
+ end
41
+
42
+ should "be able to start with a number" do
43
+ @s3.expects(:send_s3_request)
44
+
45
+ assert_nothing_raised do
46
+ @s3.create_bucket('2name')
47
+ end
48
+ end
49
+
50
+ should "not be shorter than 3 characters" do
51
+ assert_raise ArgumentError do
52
+ @s3.create_bucket('ab')
53
+ end
54
+ end
55
+
56
+ should "not be longer than 63 characters" do
57
+ assert_raise ArgumentError do
58
+ @s3.create_bucket((0..63).collect{'a'}.join)
59
+ end
60
+ end
61
+
62
+ should "succeed" do
63
+ response = stub('Http Response', :is_a? => true)
64
+ @s3.expects(:send_s3_request).returns(response)
65
+
66
+ assert @s3.create_bucket('test')
67
+ end
68
+ end
69
+
70
+ context "retrieving a list of buckets" do
71
+ setup {
72
+ xml = load_fixture('s3/buckets')
73
+ response = stub('Http Response', :body => xml)
74
+ @s3.expects(:send_s3_request).returns(response)
75
+
76
+ @result = @s3.buckets
77
+ }
78
+
79
+ should "return an array of buckets" do
80
+ assert @result.is_a?(Array)
81
+ assert_equal Awsum::S3::Bucket, @result[0].class
82
+ end
83
+ end
84
+
85
+ context "deleting a bucket" do
86
+ setup {
87
+ response = stub('Http Response', :is_a? => true)
88
+ @s3.expects(:send_s3_request).returns(response)
89
+ }
90
+
91
+ should "succeed" do
92
+ assert @s3.delete_bucket('test')
93
+ end
94
+ end
95
+
96
+ context "a bucket" do
97
+ setup {
98
+ @bucket = Awsum::S3::Bucket.new(@s3, 'test', Time.now)
99
+ }
100
+
101
+ should "be able to delete itself" do
102
+ response = stub('Http Response', :is_a? => true)
103
+ @s3.expects(:send_s3_request).returns(response)
104
+
105
+ assert @bucket.delete
106
+ end
107
+
108
+ should "be able to delete itself with Object(s)" do
109
+ xml = load_fixture('s3/keys')
110
+ response = stub('Http Response', :is_a? => true, :body => xml)
111
+ requests = sequence('requests')
112
+ ['get objects', 'delete first object', 'delete second object', 'delete bucket'].each do |process_request|
113
+ @s3.expects(:send_s3_request).returns(response).in_sequence(requests)
114
+ end
115
+
116
+ assert @bucket.delete!
117
+ end
118
+ end
119
+ end
120
+
121
+ context "Objects: " do
122
+ context "creating an object" do
123
+ context "with a string" do
124
+ setup {
125
+ response = stub('Http Response', :is_a? => true)
126
+ @s3.expects(:send_s3_request).returns(response)
127
+ }
128
+
129
+ should "send data" do
130
+ assert @s3.create_object('test', 'test.txt', 'Some text')
131
+ end
132
+ end
133
+
134
+ context "with an IO object" do
135
+ setup {
136
+ response = stub('Http Response', :is_a? => true)
137
+ @s3.expects(:process_request).returns(response)
138
+
139
+ lstat = stub('lstat', :size => 100)
140
+ @data = stub('IO', :nil? => false)
141
+ @data.expects(:respond_to?).at_least_once.returns(true)
142
+ @data.expects(:lstat).returns(lstat)
143
+ read_sequence = sequence('read_sequence')
144
+ @data.expects(:read).returns((1..100).collect{|i| 'x'}.join('')).in_sequence(read_sequence)
145
+ @data.expects(:read).returns(nil).in_sequence(read_sequence)
146
+ @data.expects(:rewind).returns(0)
147
+ }
148
+
149
+ should "send data" do
150
+ assert @s3.create_object('test', 'test.txt', @data)
151
+ end
152
+ end
153
+ end
154
+
155
+ context "deleting an object" do
156
+ setup {
157
+ response = stub('Http Response', :is_a? => true)
158
+ @s3.expects(:send_s3_request).returns(response)
159
+ }
160
+
161
+ should "succeed" do
162
+ @s3.delete_object('test', 'test.txt')
163
+ end
164
+ end
165
+
166
+ context "copying an object" do
167
+ context "to a different bucket with same key" do
168
+ setup {
169
+ response = stub('Http Response', :is_a? => true, :body => '')
170
+ @s3.expects(:send_s3_request).returns(response)
171
+ }
172
+
173
+ should "succeed" do
174
+ assert @s3.copy_object('test', 'test.txt', 'test2')
175
+ end
176
+ end
177
+
178
+ context "within the same bucket with a different key" do
179
+ setup {
180
+ response = stub('Http Response', :is_a? => true, :body => '')
181
+ @s3.expects(:send_s3_request).returns(response)
182
+ }
183
+
184
+ should "succeed" do
185
+ assert @s3.copy_object('test', 'test.txt', nil, 'test2.txt')
186
+ end
187
+ end
188
+
189
+ context "replacing headers and meta-data" do
190
+ setup {
191
+ response = stub('Http Response', :is_a? => true, :body => '')
192
+ @s3.expects(:send_s3_request).returns(response)
193
+ }
194
+
195
+ should "succeed" do
196
+ assert @s3.copy_object('test', 'test.txt', nil, nil, {'New-Header' => 'two'})
197
+ end
198
+ end
199
+
200
+ context "within the same bucket, with the same object and with no changed headers" do
201
+ should "raise an error" do
202
+ assert_raise ArgumentError do
203
+ @s3.copy_object('test', 'test.txt')
204
+ end
205
+ end
206
+ end
207
+
208
+ context "with a delayed error" do
209
+ setup {
210
+ xml = load_fixture('s3/copy_failure')
211
+ response = stub('Http Response', :is_a? => true, :code => 200, :body => xml)
212
+ @s3.expects(:send_s3_request).returns(response)
213
+ }
214
+
215
+ should "raise an error" do
216
+ assert_raise Awsum::Error do
217
+ @s3.copy_object('test', 'test.txt', 'test2')
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ context "an object" do
224
+ setup {
225
+ @object = Awsum::S3::Object.new(@s3, 'test', 'test.txt', Time.now, 'XXXXX', 234, 'AAAAAA', 'STANDARD')
226
+ }
227
+
228
+ should "be able to delete itself" do
229
+ response = stub('Http Response', :is_a? => true)
230
+ @s3.expects(:send_s3_request).returns(response)
231
+
232
+ assert @object.delete
233
+ end
234
+
235
+ should "be able to copy itself to a different key" do
236
+ response = stub('Http Response', :is_a? => true, :body => '')
237
+ @s3.expects(:send_s3_request).returns(response)
238
+
239
+ assert @object.copy('test2.txt')
240
+ end
241
+
242
+ should "be able to rename itself" do
243
+ response = stub('Http Response', :is_a? => true, :body => '')
244
+ @s3.expects(:send_s3_request).returns(response).times(2)
245
+
246
+ assert @object.rename('test2.txt')
247
+ end
248
+
249
+ should "be able to move itself" do
250
+ response = stub('Http Response', :is_a? => true, :body => '')
251
+ @s3.expects(:send_s3_request).returns(response).times(2)
252
+
253
+ assert @object.move('test2.txt')
254
+ end
255
+
256
+ should "be able to copy itself to a new bucket" do
257
+ response = stub('Http Response', :is_a? => true, :body => '')
258
+ @s3.expects(:send_s3_request).returns(response)
259
+
260
+ assert @object.copy_to('another_bucket')
261
+ end
262
+
263
+ should "be able to move itself to a new bucket" do
264
+ response = stub('Http Response', :is_a? => true, :body => '')
265
+ @s3.expects(:send_s3_request).returns(response).times(2)
266
+
267
+ assert @object.move_to('another_bucket')
268
+ end
269
+
270
+ should "be able to return it's headers" do
271
+ response = stub('Http Response')
272
+ @s3.expects(:send_s3_request).returns(response)
273
+
274
+ assert @object.headers
275
+ end
276
+
277
+ should "be able to return it's data" do
278
+ response = stub('Http Response', :body => 'test')
279
+ @s3.expects(:send_s3_request).yields(response)
280
+
281
+ assert_equal 'test', @object.data
282
+ end
283
+
284
+ should "be able to return it's data in chunks" do
285
+ response = stub('Http Response')
286
+ response.expects(:read_body).yields('test')
287
+ @s3.expects(:send_s3_request).yields(response)
288
+
289
+ data = ''
290
+ @object.data do |chunk|
291
+ data << chunk
292
+ end
293
+
294
+ assert_equal 'test', data
295
+ end
296
+ end
297
+ end
298
+ end