azure 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +36 -0
- data/README.md +3 -0
- data/Rakefile +81 -0
- data/azure.gemspec +20 -9
- data/lib/azure.rb +4 -0
- data/lib/azure/atom.rb +170 -0
- data/lib/azure/auth.rb +29 -0
- data/lib/azure/blobs.rb +620 -0
- data/lib/azure/blobs/blob.rb +360 -0
- data/lib/azure/blobs/container.rb +209 -0
- data/lib/azure/blobs/service.rb +396 -0
- data/lib/azure/blobs/shared_access_signature.rb +84 -0
- data/lib/azure/blobs/uri.rb +60 -0
- data/lib/azure/configuration.rb +121 -0
- data/lib/azure/core/auth/shared_key.rb +95 -0
- data/lib/azure/core/auth/shared_key_lite.rb +34 -0
- data/lib/azure/core/collection.rb +118 -0
- data/lib/azure/core/service.rb +43 -0
- data/lib/azure/core/signer.rb +32 -0
- data/lib/azure/core/utils/interval.rb +97 -0
- data/lib/azure/core/utils/queryable.rb +74 -0
- data/lib/azure/core/utils/storage_service_properties.rb +83 -0
- data/lib/azure/core/utils/string.rb +59 -0
- data/lib/azure/error.rb +72 -0
- data/lib/azure/queues.rb +272 -0
- data/lib/azure/queues/message.rb +174 -0
- data/lib/azure/queues/queue.rb +187 -0
- data/lib/azure/queues/service.rb +263 -0
- data/lib/azure/queues/service_properties.rb +152 -0
- data/lib/azure/queues/uri.rb +78 -0
- data/lib/azure/request.rb +102 -0
- data/lib/azure/response.rb +93 -0
- data/lib/azure/service_bus.rb +4 -0
- data/lib/azure/service_bus/auth/authorizer.rb +22 -0
- data/lib/azure/service_bus/auth/uri.rb +52 -0
- data/lib/azure/service_bus/auth/wrap.rb +37 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +76 -0
- data/lib/azure/service_bus/auth/wrap_token.rb +45 -0
- data/lib/azure/service_bus/auth/wrap_token_manager.rb +46 -0
- data/lib/azure/service_bus/brokered_message.rb +139 -0
- data/lib/azure/service_bus/brokered_message_serializer.rb +113 -0
- data/lib/azure/service_bus/queues.rb +194 -0
- data/lib/azure/service_bus/queues/queue.rb +100 -0
- data/lib/azure/service_bus/queues/queue_serializer.rb +51 -0
- data/lib/azure/service_bus/queues/service.rb +154 -0
- data/lib/azure/service_bus/queues/uri.rb +80 -0
- data/lib/azure/service_bus/rules.rb +110 -0
- data/lib/azure/service_bus/rules/rule.rb +97 -0
- data/lib/azure/service_bus/rules/service.rb +122 -0
- data/lib/azure/service_bus/rules/uri.rb +39 -0
- data/lib/azure/service_bus/service_bus_service.rb +22 -0
- data/lib/azure/service_bus/subscriptions.rb +170 -0
- data/lib/azure/service_bus/subscriptions/service.rb +133 -0
- data/lib/azure/service_bus/subscriptions/subscription.rb +164 -0
- data/lib/azure/service_bus/subscriptions/subscription_serializer.rb +74 -0
- data/lib/azure/service_bus/subscriptions/uri.rb +71 -0
- data/lib/azure/service_bus/topics.rb +120 -0
- data/lib/azure/service_bus/topics/service.rb +98 -0
- data/lib/azure/service_bus/topics/topic.rb +122 -0
- data/lib/azure/service_bus/topics/topic_serializer.rb +44 -0
- data/lib/azure/service_bus/topics/uri.rb +58 -0
- data/lib/azure/service_runtime/client/goal_state_pipe_monitor.rb +21 -0
- data/lib/azure/service_runtime/client/goal_state_protocol.rb +18 -0
- data/lib/azure/service_runtime/client/runtime_client.rb +135 -0
- data/lib/azure/service_runtime/deployment.rb +24 -0
- data/lib/azure/service_runtime/local_resource.rb +15 -0
- data/lib/azure/service_runtime/role.rb +17 -0
- data/lib/azure/service_runtime/role_environment.rb +206 -0
- data/lib/azure/service_runtime/role_environment_change.rb +32 -0
- data/lib/azure/service_runtime/role_instance.rb +35 -0
- data/lib/azure/service_runtime/role_instance_endpoint.rb +14 -0
- data/lib/azure/tables.rb +215 -0
- data/lib/azure/tables/auth/shared_key.rb +71 -0
- data/lib/azure/tables/auth/shared_key_lite.rb +30 -0
- data/lib/azure/tables/entities_collection.rb +66 -0
- data/lib/azure/tables/entity.rb +127 -0
- data/lib/azure/tables/service.rb +211 -0
- data/lib/azure/tables/table.rb +129 -0
- data/lib/azure/tables/tables_collection.rb +62 -0
- data/lib/azure/tables/types.rb +65 -0
- data/lib/azure/tables/uri.rb +62 -0
- data/test/fixtures/32px-fulls-black.jpg +0 -0
- data/test/fixtures/all_containers.xml +20 -0
- data/test/fixtures/all_tables.xml +22 -0
- data/test/fixtures/create_table_response_entry.xml +15 -0
- data/test/fixtures/error.xml +5 -0
- data/test/fixtures/insert_entity_response_entry.xml +25 -0
- data/test/fixtures/messages.xml +12 -0
- data/test/fixtures/query_entities_empty_response.xml +7 -0
- data/test/fixtures/query_entities_response.xml +45 -0
- data/test/fixtures/queue_service_properties.xml +22 -0
- data/test/fixtures/queue_service_properties_original.xml +19 -0
- data/test/fixtures/queues.xml +16 -0
- data/test/fixtures/sb_default_create_queue_response.xml +23 -0
- data/test/fixtures/sb_default_create_topic_response.xml +18 -0
- data/test/fixtures/sb_get_access_token_response.txt +1 -0
- data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
- data/test/integration/blobs/auth_test.rb +19 -0
- data/test/integration/blobs/blob_test.rb +61 -0
- data/test/integration/blobs/clear_page_range_test.rb +19 -0
- data/test/integration/blobs/copy_test.rb +33 -0
- data/test/integration/blobs/create_blobs_test.rb +51 -0
- data/test/integration/blobs/create_container_test.rb +13 -0
- data/test/integration/blobs/create_snapshot_test.rb +17 -0
- data/test/integration/blobs/delete_blob_snapshots_test.rb +19 -0
- data/test/integration/blobs/delete_blobs_test.rb +25 -0
- data/test/integration/blobs/delete_container_test.rb +24 -0
- data/test/integration/blobs/delete_snapshot_test.rb +17 -0
- data/test/integration/blobs/get_blob_snapshot_test.rb +18 -0
- data/test/integration/blobs/get_blobs_test.rb +31 -0
- data/test/integration/blobs/get_page_range_test.rb +19 -0
- data/test/integration/blobs/list_blobs_test.rb +39 -0
- data/test/integration/blobs/list_containers_test.rb +28 -0
- data/test/integration/blobs/manage_blob_leases_test.rb +45 -0
- data/test/integration/blobs/manage_blob_metadata_test.rb +51 -0
- data/test/integration/blobs/manage_blob_properties_test.rb +25 -0
- data/test/integration/blobs/manage_blob_service_properties_test.rb +38 -0
- data/test/integration/blobs/manage_container_metadata_test.rb +46 -0
- data/test/integration/blobs/manage_container_permissions_test.rb +17 -0
- data/test/integration/blobs/update_page_range_test.rb +20 -0
- data/test/integration/queues/clear_messages_test.rb +22 -0
- data/test/integration/queues/create_queue_test.rb +13 -0
- data/test/integration/queues/delete_message_test.rb +42 -0
- data/test/integration/queues/delete_queue_test.rb +24 -0
- data/test/integration/queues/get_messages_test.rb +39 -0
- data/test/integration/queues/list_queues_test.rb +43 -0
- data/test/integration/queues/manage_queue_metadata_test.rb +45 -0
- data/test/integration/queues/manage_queue_service_properties_test.rb +27 -0
- data/test/integration/queues/peek_messages_test.rb +55 -0
- data/test/integration/queues/put_message_test.rb +31 -0
- data/test/integration/queues/update_message_test.rb +46 -0
- data/test/integration/service_bus/auth_test.rb +18 -0
- data/test/integration/service_bus/queues/create_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/delete_message_from_queue_test.rb +29 -0
- data/test/integration/service_bus/queues/delete_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/get_queue_test.rb +23 -0
- data/test/integration/service_bus/queues/list_queues_test.rb +39 -0
- data/test/integration/service_bus/queues/peek_message_from_queue_test.rb +34 -0
- data/test/integration/service_bus/queues/read_and_delete_message_from_queue_test.rb +31 -0
- data/test/integration/service_bus/queues/send_message_to_queue_test.rb +22 -0
- data/test/integration/service_bus/queues/unlock_message_from_queue_test.rb +36 -0
- data/test/integration/service_bus/rules/create_rule_test.rb +19 -0
- data/test/integration/service_bus/rules/delete_rule_test.rb +17 -0
- data/test/integration/service_bus/rules/get_rule_test.rb +21 -0
- data/test/integration/service_bus/rules/list_rules_test.rb +24 -0
- data/test/integration/service_bus/rules/rule_test.rb +16 -0
- data/test/integration/service_bus/subscriptions/create_subscription_test.rb +25 -0
- data/test/integration/service_bus/subscriptions/delete_message_from_subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/delete_subscription_test.rb +30 -0
- data/test/integration/service_bus/subscriptions/fetch_subscription_test.rb +28 -0
- data/test/integration/service_bus/subscriptions/list_subscriptions_test.rb +23 -0
- data/test/integration/service_bus/subscriptions/peek_lock_message_from_subscription_test.rb +42 -0
- data/test/integration/service_bus/subscriptions/read_delete_message_from_subscription_test.rb +36 -0
- data/test/integration/service_bus/subscriptions/subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/unlock_message_from_subscription_test.rb +43 -0
- data/test/integration/service_bus/topics/create_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/delete_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/get_topic_test.rb +23 -0
- data/test/integration/service_bus/topics/list_topics_test.rb +39 -0
- data/test/integration/service_bus/topics/send_message_to_topic_test.rb +23 -0
- data/test/integration/tables/auth_test.rb +29 -0
- data/test/integration/tables/creating_tables_test.rb +16 -0
- data/test/integration/tables/delete_entity_test.rb +39 -0
- data/test/integration/tables/deleting_table_test.rb +22 -0
- data/test/integration/tables/insert_entity_test.rb +23 -0
- data/test/integration/tables/merge_entity_test.rb +28 -0
- data/test/integration/tables/query_entities_test.rb +131 -0
- data/test/integration/tables/query_tables_test.rb +63 -0
- data/test/integration/tables/update_entity_test.rb +54 -0
- data/test/integration/test_helper.rb +14 -0
- data/test/support/blobs.rb +12 -0
- data/test/support/env.rb +5 -0
- data/test/support/fixtures.rb +22 -0
- data/test/support/stubs.rb +28 -0
- data/test/support/table_names.rb +44 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/atom_test.rb +58 -0
- data/test/unit/auth_test.rb +24 -0
- data/test/unit/blobs/blob_test.rb +5 -0
- data/test/unit/blobs/container_test.rb +67 -0
- data/test/unit/blobs/service_test.rb +17 -0
- data/test/unit/blobs/shared_access_signature_test.rb +66 -0
- data/test/unit/blobs_test.rb +156 -0
- data/test/unit/core/service_test.rb +57 -0
- data/test/unit/core/utils/interval_test.rb +70 -0
- data/test/unit/core/utils/queryable_test.rb +69 -0
- data/test/unit/core/utils/storage_service_properties_test.rb +66 -0
- data/test/unit/error_test.rb +39 -0
- data/test/unit/queues/message_test.rb +40 -0
- data/test/unit/queues/queue_test.rb +64 -0
- data/test/unit/queues/service_properties.rb +35 -0
- data/test/unit/request_test.rb +38 -0
- data/test/unit/response_test.rb +43 -0
- data/test/unit/service_bus/auth/authorizer_test.rb +27 -0
- data/test/unit/service_bus/auth/wrap_token_test.rb +28 -0
- data/test/unit/service_bus/queues/queue_test.rb +38 -0
- data/test/unit/service_bus/topics/topic_test.rb +33 -0
- data/test/unit/service_runtime/data/goalstate.xml +9 -0
- data/test/unit/service_runtime/data/roleenvironmentdata.xml +29 -0
- data/test/unit/service_runtime/data/runtime.xml +6 -0
- data/test/unit/service_runtime/role_environment_test.rb +144 -0
- data/test/unit/tables/auth/shared_key_lite_test.rb +39 -0
- data/test/unit/tables/auth/shared_key_test.rb +45 -0
- data/test/unit/tables/entities_collection_test.rb +39 -0
- data/test/unit/tables/entity_test.rb +72 -0
- data/test/unit/tables/table_test.rb +57 -0
- data/test/unit/tables_test.rb +302 -0
- data/test/unit/types_test.rb +67 -0
- metadata +310 -47
- data/LICENSE +0 -0
- data/README +0 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "azure/tables/auth/shared_key_lite"
|
3
|
+
|
4
|
+
describe Azure::Tables::Auth::SharedKeyLite do
|
5
|
+
subject do
|
6
|
+
Azure::Tables::Auth::SharedKeyLite.new(
|
7
|
+
"account-name",
|
8
|
+
Base64.strict_encode64("access-key")
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "#signable_string includes the relevant bits" do
|
13
|
+
string = subject.signable_string(:get, double(path: "/path"), {
|
14
|
+
"Date" => "Time"
|
15
|
+
})
|
16
|
+
|
17
|
+
string.must_equal "Time\n/account-name/path"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#signable_string requires a Date or x-ms-date header" do
|
21
|
+
proc {
|
22
|
+
subject.signable_string(:get, double(path: "/path"), {})
|
23
|
+
}.must_raise KeyError, "Headers must include Date"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#sign will return a Base64-encoded, HMAC/SHA256-encrypted version of the signable string" do
|
27
|
+
def subject.signable_string(*)
|
28
|
+
"TestString"
|
29
|
+
end
|
30
|
+
|
31
|
+
expected = Base64.strict_encode64(
|
32
|
+
OpenSSL::HMAC.digest("sha256", "access-key", "TestString")
|
33
|
+
)
|
34
|
+
|
35
|
+
actual = subject.sign(MiniTest::Mock.new, MiniTest::Mock.new, MiniTest::Mock.new)
|
36
|
+
|
37
|
+
actual.must_equal expected
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "azure/tables/auth/shared_key"
|
3
|
+
|
4
|
+
describe Azure::Tables::Auth::SharedKey do
|
5
|
+
|
6
|
+
subject do
|
7
|
+
Azure::Tables::Auth::SharedKey.new(
|
8
|
+
"account-name",
|
9
|
+
Base64.strict_encode64("access-key")
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#signable_string includes the relevant bits" do
|
14
|
+
string = subject.signable_string(:get, double(path: "/path"), {
|
15
|
+
"Content-MD5" => "Foo",
|
16
|
+
"Content-Type" => "text/plain",
|
17
|
+
"Date" => "Time"
|
18
|
+
})
|
19
|
+
|
20
|
+
string.must_equal "GET\nFoo\ntext/plain\nTime\n/account-name/path"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "#signable_string requires a Date or x-ms-date header" do
|
24
|
+
proc {
|
25
|
+
subject.signable_string(:get, double(path: "/path"), {
|
26
|
+
"Content-MD5" => "Foo",
|
27
|
+
"Content-Type" => "text/plain"
|
28
|
+
})
|
29
|
+
}.must_raise KeyError, "Headers must include Date"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#sign will return a Base64-encoded, HMAC/SHA256-encrypted version of the signable string" do
|
33
|
+
def subject.signable_string(*)
|
34
|
+
"TestString"
|
35
|
+
end
|
36
|
+
|
37
|
+
expected = Base64.strict_encode64(
|
38
|
+
OpenSSL::HMAC.digest("sha256", "access-key", "TestString")
|
39
|
+
)
|
40
|
+
|
41
|
+
actual = subject.sign(MiniTest::Mock.new, MiniTest::Mock.new, MiniTest::Mock.new)
|
42
|
+
|
43
|
+
actual.must_equal expected
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "azure/atom"
|
3
|
+
require "azure/tables"
|
4
|
+
require "azure/tables/entities_collection"
|
5
|
+
|
6
|
+
describe Azure::Tables::EntitiesCollection do
|
7
|
+
|
8
|
+
let :service do
|
9
|
+
MiniTest::Mock.new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
@table = Azure::Tables::Table.new("table_name")
|
14
|
+
entries = Azure::Atom::Feed.load_feed(Fixtures[:query_entities_response]).entries
|
15
|
+
@collection = Azure::Tables::EntitiesCollection.from_entries(@table, entries, {}, service)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "return an instance from entries feed" do
|
19
|
+
@collection.must_be :kind_of?, Azure::Tables::EntitiesCollection
|
20
|
+
@collection.size.must_equal 2
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should indicate if the result is a paginated result" do
|
24
|
+
@collection.paginated?.must_equal false
|
25
|
+
@collection.continuation_token("part1", "row2")
|
26
|
+
@collection.paginated?.must_equal true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to set continuation tokens" do
|
30
|
+
@collection.continuation_token("part1", "row2")
|
31
|
+
|
32
|
+
service.expect(:query_entities, nil, [@table, {
|
33
|
+
"NextPartitionKey" => "part1",
|
34
|
+
"NextRowKey" => "row2"
|
35
|
+
}])
|
36
|
+
|
37
|
+
@collection.next
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'azure/tables/entity'
|
3
|
+
|
4
|
+
describe Azure::Tables::Entity do
|
5
|
+
before do
|
6
|
+
@entry = Azure::Atom::Entry.load_entry(Fixtures[:insert_entity_response_entry])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to instantiate an entity from an xml entry" do
|
10
|
+
entity = Azure::Tables::Entity.from_entry(@entry)
|
11
|
+
|
12
|
+
"Mountain View".must_equal entity["Address"]
|
13
|
+
entity["Address"].must_be :kind_of?, String
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to read/write an attribute directly" do
|
17
|
+
entity = Azure::Tables::Entity.new
|
18
|
+
entity["myField"] = "Mine"
|
19
|
+
entity["myField"].must_equal "Mine"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can reset it's attributes" do
|
23
|
+
source = Azure::Tables::Entity.new("Foo" => "Bar") do |e|
|
24
|
+
e.url = URI("http://localhost/foo")
|
25
|
+
end
|
26
|
+
|
27
|
+
target = Azure::Tables::Entity.new("Baz" => "Qux") do |e|
|
28
|
+
e.url = URI("http://localhost/bar")
|
29
|
+
end
|
30
|
+
|
31
|
+
target.reset(source)
|
32
|
+
target.url.must_equal source.url
|
33
|
+
target.attributes.must_equal source.attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to update itself" do
|
37
|
+
entity, service = entity("Foo" => "Bar")
|
38
|
+
service.expect(:update_entity, true, [entity, { "Foo" => "Qux" }])
|
39
|
+
entity.update("Foo" => "Qux")
|
40
|
+
service.verify
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be able to merge properties" do
|
44
|
+
entity, service = entity("Foo" => "Bar")
|
45
|
+
service.expect(:merge_entity, true, [entity, { "Baz" => "Qux" }])
|
46
|
+
entity.merge("Baz" => "Qux")
|
47
|
+
service.verify
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to delete itself" do
|
51
|
+
entity, service = entity({})
|
52
|
+
service.expect(:delete_entity, true, [entity])
|
53
|
+
entity.delete.must_equal true
|
54
|
+
service.verify
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can set/get the etag" do
|
58
|
+
entity_1 = Azure::Tables::Entity.new
|
59
|
+
entity_1.etag = "FooBar"
|
60
|
+
entity_1.etag.must_equal "FooBar"
|
61
|
+
|
62
|
+
entity_2 = Azure::Tables::Entity.new
|
63
|
+
entity_2.etag.must_equal "*"
|
64
|
+
end
|
65
|
+
|
66
|
+
def entity(attributes)
|
67
|
+
service = MiniTest::Mock.new
|
68
|
+
uri = URI("http://localhost/foo")
|
69
|
+
entity = Azure::Tables::Entity.new(attributes, service) { |e| e.url = uri }
|
70
|
+
[entity, service]
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "azure/tables/table"
|
3
|
+
|
4
|
+
describe Azure::Tables::Table do
|
5
|
+
def entry
|
6
|
+
Atom::Entry.load_entry(Fixtures[:create_table_response_entry])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be instantiated from an entry" do
|
10
|
+
table = Azure::Tables::Table.from_entry(entry)
|
11
|
+
table.name.must_equal "mytable"
|
12
|
+
table.url.must_equal URI("http://myaccount.table.core.windows.net/Tables('mytable')")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is equal to another table if they share the same name" do
|
16
|
+
table_1 = Azure::Tables::Table.new("mytable", URI("http://myaccount.table.core.windows.net/Tables('mytable')"))
|
17
|
+
table_2 = Azure::Tables::Table.new("mytable", URI("http://localhost/foo"))
|
18
|
+
|
19
|
+
table_1.must_equal table_2
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can delete itself" do
|
23
|
+
table, service = table("mytable")
|
24
|
+
service.expect(:delete, true, [table])
|
25
|
+
table.delete.must_equal true
|
26
|
+
service.verify
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can insert an entity" do
|
30
|
+
table, service = table("mytable")
|
31
|
+
entity = Azure::Tables::Entity.new
|
32
|
+
service.expect(:insert_entity, entity, [table, entity])
|
33
|
+
table.insert(entity)
|
34
|
+
service.verify
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can query for a list of entities by not specifying the partition/row keys" do
|
38
|
+
table, service = table("mytable")
|
39
|
+
service.expect(:query_entities, [], [table, {}])
|
40
|
+
table.entities.must_be_empty
|
41
|
+
service.verify
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can query for a specific entity" do
|
45
|
+
table, service = table("mytable")
|
46
|
+
service.expect(:query_entity, nil, [table, "Foo", "Bar", {}])
|
47
|
+
table.entities(partition_key: "Foo", row_key: "Bar").must_be_nil
|
48
|
+
service.verify
|
49
|
+
end
|
50
|
+
|
51
|
+
def table(name)
|
52
|
+
service = MiniTest::Mock.new
|
53
|
+
uri = URI("http://localhost/foo")
|
54
|
+
table = Azure::Tables::Table.new(name, uri, service)
|
55
|
+
[table, service]
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "azure/tables"
|
3
|
+
|
4
|
+
describe Azure::Tables do
|
5
|
+
class StubResponse
|
6
|
+
attr_reader :success, :body, :error
|
7
|
+
alias_method :success?, :success
|
8
|
+
|
9
|
+
def initialize(attrs={})
|
10
|
+
@success = attrs.fetch(:success, true)
|
11
|
+
@body = attrs.fetch(:body, nil)
|
12
|
+
@etag = attrs.fetch(:etag, nil)
|
13
|
+
@error = attrs.fetch(:error, nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
def headers
|
17
|
+
{ "etag" => @etag }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let :service do
|
22
|
+
MiniTest::Mock.new
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".all" do
|
26
|
+
let :successful_response do
|
27
|
+
StubResponse.new(success: true, body: Fixtures[:all_tables])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns a list of Tables on a successful call" do
|
31
|
+
service.stub(:call, successful_response)
|
32
|
+
|
33
|
+
tables = Azure::Tables.all({}, service)
|
34
|
+
tables.must_include Azure::Tables::Table.new("mytable", nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".create" do
|
39
|
+
let :successful_response do
|
40
|
+
double(success?: true, body: Fixtures[:create_table_response_entry])
|
41
|
+
end
|
42
|
+
|
43
|
+
let :failed_response do
|
44
|
+
double(success?: false, body: Fixtures[:error], error: Object.new)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns a valid table when successful" do
|
48
|
+
service.stub(:call, successful_response)
|
49
|
+
|
50
|
+
table = Azure::Tables.create("mytable", service)
|
51
|
+
assert table.valid?
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns an invalid table when unsuccessful" do
|
55
|
+
service.stub(:call, failed_response)
|
56
|
+
|
57
|
+
table = Azure::Tables.create("mytable", service)
|
58
|
+
refute table.valid?
|
59
|
+
table.error.must_equal failed_response.error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".delete" do
|
64
|
+
let :successful_response do
|
65
|
+
double(success?: true)
|
66
|
+
end
|
67
|
+
|
68
|
+
let :failed_response do
|
69
|
+
double(success?: false, error: Object.new)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns true when successful" do
|
73
|
+
table = Azure::Tables::Table.new("mytable", URI("http://localhost/foo"))
|
74
|
+
service.stub(:call, successful_response)
|
75
|
+
|
76
|
+
result = Azure::Tables.delete(table, service)
|
77
|
+
result.must_equal true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns false when failed" do
|
81
|
+
table = Azure::Tables::Table.new("mytable", URI("http://localhost/foo"))
|
82
|
+
service.stub(:call, failed_response)
|
83
|
+
|
84
|
+
result = Azure::Tables.delete(table, service)
|
85
|
+
result.must_equal false
|
86
|
+
refute table.valid?
|
87
|
+
table.error.must_equal failed_response.error
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe ".insert_entity" do
|
92
|
+
let :successful_response do
|
93
|
+
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
|
94
|
+
end
|
95
|
+
|
96
|
+
let :failed_response do
|
97
|
+
double(success?: false, error: Object.new)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns the entity when successful" do
|
101
|
+
table = Azure::Tables::Table.new("mytable")
|
102
|
+
entity = Azure::Tables::Entity.new
|
103
|
+
|
104
|
+
service.stub(:call, successful_response)
|
105
|
+
|
106
|
+
Azure::Tables.insert_entity(table, entity, service)
|
107
|
+
entity.etag.must_equal "Foo"
|
108
|
+
entity["Address"].to_s.must_equal "Mountain View"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "adds an error to the entity when unsusccessful" do
|
112
|
+
table = Azure::Tables::Table.new("mytable")
|
113
|
+
entity = Azure::Tables::Entity.new
|
114
|
+
|
115
|
+
service.stub(:call, failed_response)
|
116
|
+
|
117
|
+
Azure::Tables.insert_entity(table, entity, service)
|
118
|
+
entity.etag.must_equal Azure::Tables::Entity::FORCE_UPDATE
|
119
|
+
entity.error.must_equal failed_response.error
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe ".update_entity" do
|
124
|
+
let :successful_response do
|
125
|
+
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
|
126
|
+
end
|
127
|
+
|
128
|
+
let :failed_response do
|
129
|
+
double(success?: false, error: Object.new)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "replaces the entity's attributes if successful" do
|
133
|
+
entity = Azure::Tables::Entity.new
|
134
|
+
attrs = { "Foo" => "Bar", "Baz" => "Qux" }
|
135
|
+
|
136
|
+
service.stub(:call, successful_response)
|
137
|
+
|
138
|
+
Azure::Tables.update_entity(entity, attrs, false, service)
|
139
|
+
entity.attributes.must_equal attrs
|
140
|
+
entity.etag.must_equal successful_response.headers["etag"]
|
141
|
+
assert entity.valid?
|
142
|
+
end
|
143
|
+
|
144
|
+
it "doesn't change the entity if failed" do
|
145
|
+
entity = Azure::Tables::Entity.new
|
146
|
+
attrs = { "Foo" => "Bar" }
|
147
|
+
|
148
|
+
service.stub(:call, failed_response)
|
149
|
+
|
150
|
+
Azure::Tables.update_entity(entity, attrs, false, service)
|
151
|
+
entity.attributes.wont_equal attrs
|
152
|
+
entity.etag.wont_equal successful_response.headers["etag"]
|
153
|
+
entity.error.must_equal failed_response.error
|
154
|
+
refute entity.valid?
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe ".merge_entity" do
|
159
|
+
let :successful_response do
|
160
|
+
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry], etag: "Foo")
|
161
|
+
end
|
162
|
+
|
163
|
+
let :failed_response do
|
164
|
+
double(success?: false, error: Object.new)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "updates the entity's attributes if successful" do
|
168
|
+
entity = Azure::Tables::Entity.new("Qux" => "Bar")
|
169
|
+
attrs = { "Foo" => "Bar", "Baz" => "Qux" }
|
170
|
+
|
171
|
+
service.stub(:call, successful_response)
|
172
|
+
|
173
|
+
Azure::Tables.merge_entity(entity, attrs, false, service)
|
174
|
+
entity["Qux"].must_equal "Bar"
|
175
|
+
entity["Foo"].must_equal "Bar"
|
176
|
+
entity["Baz"].must_equal "Qux"
|
177
|
+
entity.etag.must_equal successful_response.headers["etag"]
|
178
|
+
assert entity.valid?
|
179
|
+
end
|
180
|
+
|
181
|
+
it "doesn't change the entity if failed" do
|
182
|
+
entity = Azure::Tables::Entity.new("Qux" => "Bar")
|
183
|
+
attrs = { "Foo" => "Bar", "Baz" => "Qux" }
|
184
|
+
|
185
|
+
service.stub(:call, failed_response)
|
186
|
+
|
187
|
+
Azure::Tables.merge_entity(entity, attrs, false, service)
|
188
|
+
entity.attributes.must_equal({ "Qux" => "Bar" })
|
189
|
+
entity.etag.wont_equal successful_response.headers["etag"]
|
190
|
+
entity.error.must_equal failed_response.error
|
191
|
+
refute entity.valid?
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe ".delete_entity" do
|
196
|
+
let :successful_response do
|
197
|
+
StubResponse.new(success: true, etag: "Foo")
|
198
|
+
end
|
199
|
+
|
200
|
+
let :failed_response do
|
201
|
+
double(success?: false, error: Object.new)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "freezes the entity if successful" do
|
205
|
+
entity = Azure::Tables::Entity.new("Qux" => "Bar")
|
206
|
+
|
207
|
+
service.stub(:call, successful_response)
|
208
|
+
|
209
|
+
Azure::Tables.delete_entity(entity, false, service)
|
210
|
+
entity.etag.must_equal successful_response.headers["etag"]
|
211
|
+
assert entity.frozen?
|
212
|
+
assert entity.valid?
|
213
|
+
end
|
214
|
+
|
215
|
+
it "sets the error on the entity if failed" do
|
216
|
+
entity = Azure::Tables::Entity.new("Qux" => "Bar")
|
217
|
+
|
218
|
+
service.stub(:call, failed_response)
|
219
|
+
|
220
|
+
Azure::Tables.delete_entity(entity, false, service)
|
221
|
+
entity.etag.wont_equal successful_response.headers["etag"]
|
222
|
+
entity.error.must_equal failed_response.error
|
223
|
+
refute entity.frozen?
|
224
|
+
refute entity.valid?
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe ".query_entities" do
|
229
|
+
let :successful_response do
|
230
|
+
StubResponse.new(success: true, body: Fixtures[:query_entities_response])
|
231
|
+
end
|
232
|
+
|
233
|
+
let :empty_response do
|
234
|
+
StubResponse.new(success: true, body: Fixtures[:query_entities_empty_response])
|
235
|
+
end
|
236
|
+
|
237
|
+
let :failed_response do
|
238
|
+
double(success?: false, error: Object.new)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "returns a list of entities when successful" do
|
242
|
+
table = Azure::Tables::Table.new("mytable")
|
243
|
+
|
244
|
+
service.stub(:call, successful_response)
|
245
|
+
|
246
|
+
entities = Azure::Tables.query_entities(table, {}, service)
|
247
|
+
entities.must_be :kind_of?, Azure::Tables::EntitiesCollection
|
248
|
+
entities.size.must_equal 2
|
249
|
+
entities.first["Name"].to_s.must_equal "John"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "returns an empty list when successful but the response is empty" do
|
253
|
+
table = Azure::Tables::Table.new("mytable")
|
254
|
+
|
255
|
+
service.stub(:call, empty_response)
|
256
|
+
|
257
|
+
entities = Azure::Tables.query_entities(table, {}, service)
|
258
|
+
entities.must_be_empty
|
259
|
+
end
|
260
|
+
|
261
|
+
it "returns an empty list if the request is unsuccessful" do
|
262
|
+
# TODO: We need a way to pass the error to the end user.
|
263
|
+
|
264
|
+
table = Azure::Tables::Table.new("mytable")
|
265
|
+
|
266
|
+
service.stub(:call, failed_response)
|
267
|
+
|
268
|
+
entities = Azure::Tables.query_entities(table, {}, service)
|
269
|
+
entities.must_be_empty
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe ".query_entity" do
|
274
|
+
let :successful_response do
|
275
|
+
StubResponse.new(success: true, body: Fixtures[:insert_entity_response_entry])
|
276
|
+
end
|
277
|
+
|
278
|
+
let :failed_response do
|
279
|
+
double(success?: false, error: Object.new)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "returns the matching entity when it's successful" do
|
283
|
+
table = Azure::Tables::Table.new("mytable")
|
284
|
+
|
285
|
+
service.stub(:call, successful_response)
|
286
|
+
|
287
|
+
entity = Azure::Tables.query_entity(table, "PK", "RK", {}, service)
|
288
|
+
entity["PartitionKey"].to_s.must_equal "mypartitionkey"
|
289
|
+
end
|
290
|
+
|
291
|
+
it "returns nil if the request is unsuccessful" do
|
292
|
+
# TODO: We need a way to pass the error to the end user.
|
293
|
+
|
294
|
+
table = Azure::Tables::Table.new("mytable")
|
295
|
+
|
296
|
+
service.stub(:call, failed_response)
|
297
|
+
|
298
|
+
entities = Azure::Tables.query_entity(table, "PK", "RK", {}, service)
|
299
|
+
entities.must_be_nil
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|