azure 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +36 -0
  3. data/README.md +3 -0
  4. data/Rakefile +81 -0
  5. data/azure.gemspec +20 -9
  6. data/lib/azure.rb +4 -0
  7. data/lib/azure/atom.rb +170 -0
  8. data/lib/azure/auth.rb +29 -0
  9. data/lib/azure/blobs.rb +620 -0
  10. data/lib/azure/blobs/blob.rb +360 -0
  11. data/lib/azure/blobs/container.rb +209 -0
  12. data/lib/azure/blobs/service.rb +396 -0
  13. data/lib/azure/blobs/shared_access_signature.rb +84 -0
  14. data/lib/azure/blobs/uri.rb +60 -0
  15. data/lib/azure/configuration.rb +121 -0
  16. data/lib/azure/core/auth/shared_key.rb +95 -0
  17. data/lib/azure/core/auth/shared_key_lite.rb +34 -0
  18. data/lib/azure/core/collection.rb +118 -0
  19. data/lib/azure/core/service.rb +43 -0
  20. data/lib/azure/core/signer.rb +32 -0
  21. data/lib/azure/core/utils/interval.rb +97 -0
  22. data/lib/azure/core/utils/queryable.rb +74 -0
  23. data/lib/azure/core/utils/storage_service_properties.rb +83 -0
  24. data/lib/azure/core/utils/string.rb +59 -0
  25. data/lib/azure/error.rb +72 -0
  26. data/lib/azure/queues.rb +272 -0
  27. data/lib/azure/queues/message.rb +174 -0
  28. data/lib/azure/queues/queue.rb +187 -0
  29. data/lib/azure/queues/service.rb +263 -0
  30. data/lib/azure/queues/service_properties.rb +152 -0
  31. data/lib/azure/queues/uri.rb +78 -0
  32. data/lib/azure/request.rb +102 -0
  33. data/lib/azure/response.rb +93 -0
  34. data/lib/azure/service_bus.rb +4 -0
  35. data/lib/azure/service_bus/auth/authorizer.rb +22 -0
  36. data/lib/azure/service_bus/auth/uri.rb +52 -0
  37. data/lib/azure/service_bus/auth/wrap.rb +37 -0
  38. data/lib/azure/service_bus/auth/wrap_service.rb +76 -0
  39. data/lib/azure/service_bus/auth/wrap_token.rb +45 -0
  40. data/lib/azure/service_bus/auth/wrap_token_manager.rb +46 -0
  41. data/lib/azure/service_bus/brokered_message.rb +139 -0
  42. data/lib/azure/service_bus/brokered_message_serializer.rb +113 -0
  43. data/lib/azure/service_bus/queues.rb +194 -0
  44. data/lib/azure/service_bus/queues/queue.rb +100 -0
  45. data/lib/azure/service_bus/queues/queue_serializer.rb +51 -0
  46. data/lib/azure/service_bus/queues/service.rb +154 -0
  47. data/lib/azure/service_bus/queues/uri.rb +80 -0
  48. data/lib/azure/service_bus/rules.rb +110 -0
  49. data/lib/azure/service_bus/rules/rule.rb +97 -0
  50. data/lib/azure/service_bus/rules/service.rb +122 -0
  51. data/lib/azure/service_bus/rules/uri.rb +39 -0
  52. data/lib/azure/service_bus/service_bus_service.rb +22 -0
  53. data/lib/azure/service_bus/subscriptions.rb +170 -0
  54. data/lib/azure/service_bus/subscriptions/service.rb +133 -0
  55. data/lib/azure/service_bus/subscriptions/subscription.rb +164 -0
  56. data/lib/azure/service_bus/subscriptions/subscription_serializer.rb +74 -0
  57. data/lib/azure/service_bus/subscriptions/uri.rb +71 -0
  58. data/lib/azure/service_bus/topics.rb +120 -0
  59. data/lib/azure/service_bus/topics/service.rb +98 -0
  60. data/lib/azure/service_bus/topics/topic.rb +122 -0
  61. data/lib/azure/service_bus/topics/topic_serializer.rb +44 -0
  62. data/lib/azure/service_bus/topics/uri.rb +58 -0
  63. data/lib/azure/service_runtime/client/goal_state_pipe_monitor.rb +21 -0
  64. data/lib/azure/service_runtime/client/goal_state_protocol.rb +18 -0
  65. data/lib/azure/service_runtime/client/runtime_client.rb +135 -0
  66. data/lib/azure/service_runtime/deployment.rb +24 -0
  67. data/lib/azure/service_runtime/local_resource.rb +15 -0
  68. data/lib/azure/service_runtime/role.rb +17 -0
  69. data/lib/azure/service_runtime/role_environment.rb +206 -0
  70. data/lib/azure/service_runtime/role_environment_change.rb +32 -0
  71. data/lib/azure/service_runtime/role_instance.rb +35 -0
  72. data/lib/azure/service_runtime/role_instance_endpoint.rb +14 -0
  73. data/lib/azure/tables.rb +215 -0
  74. data/lib/azure/tables/auth/shared_key.rb +71 -0
  75. data/lib/azure/tables/auth/shared_key_lite.rb +30 -0
  76. data/lib/azure/tables/entities_collection.rb +66 -0
  77. data/lib/azure/tables/entity.rb +127 -0
  78. data/lib/azure/tables/service.rb +211 -0
  79. data/lib/azure/tables/table.rb +129 -0
  80. data/lib/azure/tables/tables_collection.rb +62 -0
  81. data/lib/azure/tables/types.rb +65 -0
  82. data/lib/azure/tables/uri.rb +62 -0
  83. data/test/fixtures/32px-fulls-black.jpg +0 -0
  84. data/test/fixtures/all_containers.xml +20 -0
  85. data/test/fixtures/all_tables.xml +22 -0
  86. data/test/fixtures/create_table_response_entry.xml +15 -0
  87. data/test/fixtures/error.xml +5 -0
  88. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  89. data/test/fixtures/messages.xml +12 -0
  90. data/test/fixtures/query_entities_empty_response.xml +7 -0
  91. data/test/fixtures/query_entities_response.xml +45 -0
  92. data/test/fixtures/queue_service_properties.xml +22 -0
  93. data/test/fixtures/queue_service_properties_original.xml +19 -0
  94. data/test/fixtures/queues.xml +16 -0
  95. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  96. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  97. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  98. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  99. data/test/integration/blobs/auth_test.rb +19 -0
  100. data/test/integration/blobs/blob_test.rb +61 -0
  101. data/test/integration/blobs/clear_page_range_test.rb +19 -0
  102. data/test/integration/blobs/copy_test.rb +33 -0
  103. data/test/integration/blobs/create_blobs_test.rb +51 -0
  104. data/test/integration/blobs/create_container_test.rb +13 -0
  105. data/test/integration/blobs/create_snapshot_test.rb +17 -0
  106. data/test/integration/blobs/delete_blob_snapshots_test.rb +19 -0
  107. data/test/integration/blobs/delete_blobs_test.rb +25 -0
  108. data/test/integration/blobs/delete_container_test.rb +24 -0
  109. data/test/integration/blobs/delete_snapshot_test.rb +17 -0
  110. data/test/integration/blobs/get_blob_snapshot_test.rb +18 -0
  111. data/test/integration/blobs/get_blobs_test.rb +31 -0
  112. data/test/integration/blobs/get_page_range_test.rb +19 -0
  113. data/test/integration/blobs/list_blobs_test.rb +39 -0
  114. data/test/integration/blobs/list_containers_test.rb +28 -0
  115. data/test/integration/blobs/manage_blob_leases_test.rb +45 -0
  116. data/test/integration/blobs/manage_blob_metadata_test.rb +51 -0
  117. data/test/integration/blobs/manage_blob_properties_test.rb +25 -0
  118. data/test/integration/blobs/manage_blob_service_properties_test.rb +38 -0
  119. data/test/integration/blobs/manage_container_metadata_test.rb +46 -0
  120. data/test/integration/blobs/manage_container_permissions_test.rb +17 -0
  121. data/test/integration/blobs/update_page_range_test.rb +20 -0
  122. data/test/integration/queues/clear_messages_test.rb +22 -0
  123. data/test/integration/queues/create_queue_test.rb +13 -0
  124. data/test/integration/queues/delete_message_test.rb +42 -0
  125. data/test/integration/queues/delete_queue_test.rb +24 -0
  126. data/test/integration/queues/get_messages_test.rb +39 -0
  127. data/test/integration/queues/list_queues_test.rb +43 -0
  128. data/test/integration/queues/manage_queue_metadata_test.rb +45 -0
  129. data/test/integration/queues/manage_queue_service_properties_test.rb +27 -0
  130. data/test/integration/queues/peek_messages_test.rb +55 -0
  131. data/test/integration/queues/put_message_test.rb +31 -0
  132. data/test/integration/queues/update_message_test.rb +46 -0
  133. data/test/integration/service_bus/auth_test.rb +18 -0
  134. data/test/integration/service_bus/queues/create_queue_test.rb +25 -0
  135. data/test/integration/service_bus/queues/delete_message_from_queue_test.rb +29 -0
  136. data/test/integration/service_bus/queues/delete_queue_test.rb +25 -0
  137. data/test/integration/service_bus/queues/get_queue_test.rb +23 -0
  138. data/test/integration/service_bus/queues/list_queues_test.rb +39 -0
  139. data/test/integration/service_bus/queues/peek_message_from_queue_test.rb +34 -0
  140. data/test/integration/service_bus/queues/read_and_delete_message_from_queue_test.rb +31 -0
  141. data/test/integration/service_bus/queues/send_message_to_queue_test.rb +22 -0
  142. data/test/integration/service_bus/queues/unlock_message_from_queue_test.rb +36 -0
  143. data/test/integration/service_bus/rules/create_rule_test.rb +19 -0
  144. data/test/integration/service_bus/rules/delete_rule_test.rb +17 -0
  145. data/test/integration/service_bus/rules/get_rule_test.rb +21 -0
  146. data/test/integration/service_bus/rules/list_rules_test.rb +24 -0
  147. data/test/integration/service_bus/rules/rule_test.rb +16 -0
  148. data/test/integration/service_bus/subscriptions/create_subscription_test.rb +25 -0
  149. data/test/integration/service_bus/subscriptions/delete_message_from_subscription_test.rb +31 -0
  150. data/test/integration/service_bus/subscriptions/delete_subscription_test.rb +30 -0
  151. data/test/integration/service_bus/subscriptions/fetch_subscription_test.rb +28 -0
  152. data/test/integration/service_bus/subscriptions/list_subscriptions_test.rb +23 -0
  153. data/test/integration/service_bus/subscriptions/peek_lock_message_from_subscription_test.rb +42 -0
  154. data/test/integration/service_bus/subscriptions/read_delete_message_from_subscription_test.rb +36 -0
  155. data/test/integration/service_bus/subscriptions/subscription_test.rb +31 -0
  156. data/test/integration/service_bus/subscriptions/unlock_message_from_subscription_test.rb +43 -0
  157. data/test/integration/service_bus/topics/create_topic_test.rb +25 -0
  158. data/test/integration/service_bus/topics/delete_topic_test.rb +25 -0
  159. data/test/integration/service_bus/topics/get_topic_test.rb +23 -0
  160. data/test/integration/service_bus/topics/list_topics_test.rb +39 -0
  161. data/test/integration/service_bus/topics/send_message_to_topic_test.rb +23 -0
  162. data/test/integration/tables/auth_test.rb +29 -0
  163. data/test/integration/tables/creating_tables_test.rb +16 -0
  164. data/test/integration/tables/delete_entity_test.rb +39 -0
  165. data/test/integration/tables/deleting_table_test.rb +22 -0
  166. data/test/integration/tables/insert_entity_test.rb +23 -0
  167. data/test/integration/tables/merge_entity_test.rb +28 -0
  168. data/test/integration/tables/query_entities_test.rb +131 -0
  169. data/test/integration/tables/query_tables_test.rb +63 -0
  170. data/test/integration/tables/update_entity_test.rb +54 -0
  171. data/test/integration/test_helper.rb +14 -0
  172. data/test/support/blobs.rb +12 -0
  173. data/test/support/env.rb +5 -0
  174. data/test/support/fixtures.rb +22 -0
  175. data/test/support/stubs.rb +28 -0
  176. data/test/support/table_names.rb +44 -0
  177. data/test/test_helper.rb +10 -0
  178. data/test/unit/atom_test.rb +58 -0
  179. data/test/unit/auth_test.rb +24 -0
  180. data/test/unit/blobs/blob_test.rb +5 -0
  181. data/test/unit/blobs/container_test.rb +67 -0
  182. data/test/unit/blobs/service_test.rb +17 -0
  183. data/test/unit/blobs/shared_access_signature_test.rb +66 -0
  184. data/test/unit/blobs_test.rb +156 -0
  185. data/test/unit/core/service_test.rb +57 -0
  186. data/test/unit/core/utils/interval_test.rb +70 -0
  187. data/test/unit/core/utils/queryable_test.rb +69 -0
  188. data/test/unit/core/utils/storage_service_properties_test.rb +66 -0
  189. data/test/unit/error_test.rb +39 -0
  190. data/test/unit/queues/message_test.rb +40 -0
  191. data/test/unit/queues/queue_test.rb +64 -0
  192. data/test/unit/queues/service_properties.rb +35 -0
  193. data/test/unit/request_test.rb +38 -0
  194. data/test/unit/response_test.rb +43 -0
  195. data/test/unit/service_bus/auth/authorizer_test.rb +27 -0
  196. data/test/unit/service_bus/auth/wrap_token_test.rb +28 -0
  197. data/test/unit/service_bus/queues/queue_test.rb +38 -0
  198. data/test/unit/service_bus/topics/topic_test.rb +33 -0
  199. data/test/unit/service_runtime/data/goalstate.xml +9 -0
  200. data/test/unit/service_runtime/data/roleenvironmentdata.xml +29 -0
  201. data/test/unit/service_runtime/data/runtime.xml +6 -0
  202. data/test/unit/service_runtime/role_environment_test.rb +144 -0
  203. data/test/unit/tables/auth/shared_key_lite_test.rb +39 -0
  204. data/test/unit/tables/auth/shared_key_test.rb +45 -0
  205. data/test/unit/tables/entities_collection_test.rb +39 -0
  206. data/test/unit/tables/entity_test.rb +72 -0
  207. data/test/unit/tables/table_test.rb +57 -0
  208. data/test/unit/tables_test.rb +302 -0
  209. data/test/unit/types_test.rb +67 -0
  210. metadata +310 -47
  211. data/LICENSE +0 -0
  212. data/README +0 -0
@@ -0,0 +1,156 @@
1
+ require "test_helper"
2
+ require "azure/blobs"
3
+
4
+ describe Azure::Blobs do
5
+ let :service do
6
+ MiniTest::Mock.new
7
+ end
8
+
9
+ describe ".containers" do
10
+ let :successful_response do
11
+ double(success?: true, body: Fixtures[:all_containers])
12
+ end
13
+
14
+ it "returns a list of Containers on a successful call" do
15
+ service.stub(:call, successful_response)
16
+
17
+ containers = Azure::Blobs.containers(service)
18
+ containers.must_include Azure::Blobs::Container.new("container-name")
19
+ end
20
+ end
21
+
22
+ describe ".create_container" do
23
+ let :successful_response do
24
+ double(success?: true)
25
+ end
26
+
27
+ let :failed_response do
28
+ double(success?: false, error: Object.new)
29
+ end
30
+
31
+ it "returns a valid container when successful" do
32
+ service.stub(:call, successful_response)
33
+
34
+ container = Azure::Blobs.create_container("mycontainer", {}, Azure::Blobs::Container::PRIVATE, service)
35
+ container.name.must_equal "mycontainer"
36
+ assert container.valid?
37
+ end
38
+
39
+ it "returns an invalid container when failed" do
40
+ service.stub(:call, failed_response)
41
+
42
+ container = Azure::Blobs.create_container("mycontainer", {}, Azure::Blobs::Container::PRIVATE, service)
43
+ container.name.must_be_nil
44
+ refute container.valid?
45
+ container.error.must_equal failed_response.error
46
+ end
47
+ end
48
+
49
+ describe ".delete_container" do
50
+ let :successful_response do
51
+ double(success?: true)
52
+ end
53
+
54
+ let :failed_response do
55
+ double(success?: false, error: Object.new)
56
+ end
57
+
58
+ let :container do
59
+ Azure::Blobs::Container.new("mycontainer")
60
+ end
61
+
62
+ it "returns true when successful and freezes the container" do
63
+ service.stub(:call, successful_response)
64
+
65
+ result = Azure::Blobs.delete_container(container, service)
66
+ result.must_equal true
67
+ assert container.frozen?
68
+ end
69
+
70
+ it "returns false when failed" do
71
+ service.stub(:call, failed_response)
72
+
73
+ result = Azure::Blobs.delete_container(container, service)
74
+ result.must_equal false
75
+ container.error.must_equal failed_response.error
76
+ refute container.frozen?
77
+ refute container.valid?
78
+ end
79
+ end
80
+
81
+ describe ".load_container_metadata" do
82
+ let :successful_response do
83
+ double(success?: true, headers: headers)
84
+ end
85
+
86
+ let :failed_response do
87
+ double(success?: false, headers: headers, error: Object.new)
88
+ end
89
+
90
+ let :headers do
91
+ { "x-ms-meta-Name" => "FooBar",
92
+ "x-ms-meta-Version" => "1.0",
93
+ "ETag" => "Blah" }
94
+ end
95
+
96
+ let :container do
97
+ Azure::Blobs::Container.new("mycontainer")
98
+ end
99
+
100
+ it "returns the subset of response headers that start with x-ms-meta- when successful" do
101
+ service.stub(:call, successful_response)
102
+
103
+ metadata = Azure::Blobs.load_container_metadata(container, service)
104
+ metadata["Name"].must_equal "FooBar"
105
+ metadata["Version"].must_equal "1.0"
106
+ metadata.size.must_equal 2
107
+ end
108
+
109
+ it "updates the container's metadata if successful" do
110
+ service.stub(:call, successful_response)
111
+
112
+ Azure::Blobs.load_container_metadata(container, service)
113
+ container.metadata.must_equal("Name" => "FooBar", "Version" => "1.0")
114
+ end
115
+
116
+ it "invalidates the container on failure" do
117
+ service.stub(:call, failed_response)
118
+
119
+ metadata = Azure::Blobs.load_container_metadata(container, service)
120
+ metadata.must_equal({})
121
+ container.metadata.wont_equal headers
122
+ container.error.must_equal failed_response.error
123
+ refute container.valid?
124
+ end
125
+ end
126
+
127
+ describe ".save_container_metadata" do
128
+ let :successful_response do
129
+ double(success?: true)
130
+ end
131
+
132
+ let :failed_response do
133
+ double(success?: false, error: Object.new)
134
+ end
135
+
136
+ let :container do
137
+ Azure::Blobs::Container.new("mycontainer")
138
+ end
139
+
140
+ it "returns true when successful" do
141
+ service.stub(:call, successful_response)
142
+
143
+ result = Azure::Blobs.save_container_metadata(container, service)
144
+ result.must_equal true
145
+ end
146
+
147
+ it "invalidates the container and returns false on failure" do
148
+ service.stub(:call, failed_response)
149
+
150
+ result = Azure::Blobs.save_container_metadata(container, service)
151
+ result.must_equal false
152
+ container.error.must_equal failed_response.error
153
+ refute container.valid?
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,57 @@
1
+ require "test_helper"
2
+ require "azure/core/service"
3
+
4
+ describe Azure::Core::Service do
5
+ let :signer do
6
+ double()
7
+ end
8
+
9
+ let :request do
10
+ req = MiniTest::Mock.new
11
+ req.stub(:request!, response)
12
+ req
13
+ end
14
+
15
+ let :response do
16
+ double()
17
+ end
18
+
19
+ let :request_factory do
20
+ rf = MiniTest::Mock.new
21
+ rf.stub(:new, request)
22
+ rf
23
+ end
24
+
25
+ let :authorizer do
26
+ auth = MiniTest::Mock.new
27
+ auth.stub(:sign)
28
+ auth
29
+ end
30
+
31
+ subject do
32
+ Azure::Core::Service.new(signer, authorizer)
33
+ end
34
+
35
+ it "instantiates a new request and signs it" do
36
+ request_factory.expect(:new, request, [:get, "/", nil])
37
+ authorizer.expect(:sign, request, [request, signer])
38
+
39
+ subject.call(:get, "/", nil, request_factory)
40
+
41
+ request_factory.verify
42
+ authorizer.verify
43
+ end
44
+
45
+ it "returns the response" do
46
+ resp = subject.call(:get, "/", nil, request_factory)
47
+ resp.must_equal response
48
+ end
49
+
50
+ it "yields the request before signing it" do
51
+ subject.call(:get, "/", nil, request_factory) do |req|
52
+ authorizer.expect(:sign, req, [req, signer])
53
+ end
54
+
55
+ authorizer.verify
56
+ end
57
+ end
@@ -0,0 +1,70 @@
1
+ require "test_helper"
2
+ require "azure/core/utils/interval"
3
+
4
+ describe Azure::Core::Utils::Interval do
5
+ let :described_class do
6
+ Azure::Core::Utils::Interval
7
+ end
8
+
9
+ describe ".parse" do
10
+ def self.assert_parses(interval_string, seconds)
11
+ it "parses #{interval_string.inspect} into #{seconds.inspect}s" do
12
+ described_class.parse(interval_string).must_equal seconds
13
+ end
14
+ end
15
+
16
+ assert_parses "P1D", 86400
17
+ assert_parses "P1DT0S", 86400
18
+ assert_parses "PT1H", 3600
19
+ assert_parses "PT1M", 60
20
+ assert_parses "PT1S", 1
21
+
22
+ assert_parses "PT0.12S", 0.12
23
+
24
+ assert_parses "P1DT1H1M1S", 90061
25
+ assert_parses "P8DT3H24M15.12S", 703455.12
26
+ end
27
+
28
+ describe ".try_convert" do
29
+ it "creates an Interval out of a number" do
30
+ result = described_class.try_convert(10.5)
31
+ result.class.must_equal described_class
32
+ result.must_equal 10.5
33
+ end
34
+
35
+ it "creates an Interval out of a properly formatted string" do
36
+ result = described_class.try_convert("PT1H")
37
+ result.class.must_equal described_class
38
+ result.must_equal 3600
39
+ end
40
+
41
+ it "returns nil if passed a malformed string" do
42
+ result = described_class.try_convert("WAT?")
43
+ result.must_be_nil
44
+ end
45
+
46
+ it "returns nil if passed nil" do
47
+ result = described_class.try_convert(nil)
48
+ result.must_be_nil
49
+ end
50
+ end
51
+
52
+ describe "#to_s" do
53
+ def self.assert_converts(seconds, interval_string)
54
+ it "converts #{seconds.inspect}s into #{interval_string.inspect}" do
55
+ described_class.new(seconds).to_s.must_equal interval_string
56
+ end
57
+ end
58
+
59
+ assert_converts 86400, "P1D"
60
+ assert_converts 3600, "PT1H"
61
+ assert_converts 60, "PT1M"
62
+ assert_converts 1, "PT1S"
63
+ assert_converts 0, "PT0S"
64
+
65
+ assert_converts 0.12, "PT0.12S"
66
+
67
+ assert_converts 90061, "P1DT1H1M1S"
68
+ assert_converts 703455.5, "P8DT3H24M15.5S"
69
+ end
70
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+ require 'azure/core/utils/queryable'
3
+
4
+ describe Azure::Core::Utils::Queryable do
5
+
6
+ include Azure::Core::Utils::Queryable
7
+
8
+ describe "Translating a hash of options" do
9
+ it "accept :skip" do
10
+ opts = { :skip => 2 }
11
+ translate_options_hash(opts).must_equal({ '$skip' => 2 })
12
+ end
13
+
14
+ it "accept :top" do
15
+ opts = { :top => 3 }
16
+ translate_options_hash(opts).must_equal({ '$top' => 3 })
17
+ end
18
+ end
19
+
20
+ describe "Building query strings" do
21
+ it "should build an empty string" do
22
+ query = {}
23
+ build_query(query).must_equal nil
24
+ end
25
+
26
+ it "should accept :select" do
27
+ query = {
28
+ :select => ["FirstName", "Email"]
29
+ }
30
+ build_query(query).must_equal "$select=FirstName,Email"
31
+ end
32
+
33
+ it "should accept :top" do
34
+ query = {
35
+ :top => 5
36
+ }
37
+ build_query(query).must_equal "$top=5"
38
+ end
39
+
40
+ it "should accept :filter" do
41
+ query = {
42
+ :filter => "FirstName eq 'Alfred'"
43
+ }
44
+ build_query(query).must_equal "$filter=FirstName%20eq%20'Alfred'"
45
+ end
46
+
47
+ it "should accept NextTableName" do
48
+ query = {
49
+ "NextTableName" => "my_table"
50
+ }
51
+ build_query(query).must_equal "NextTableName=my_table"
52
+ end
53
+
54
+ it "should accept NextPartitionKey and NextRowKey" do
55
+ query = {
56
+ "NextPartitionKey" => "part1",
57
+ "NextRowKey" => "row1",
58
+ }
59
+ build_query(query).must_equal "NextPartitionKey=part1&NextRowKey=row1"
60
+ end
61
+
62
+ it "should accept :skip" do
63
+ query = {
64
+ :skip => 2
65
+ }
66
+ build_query(query).must_equal "$skip=2"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+ require 'azure/core/utils/storage_service_properties'
3
+
4
+ describe Azure::Core::Utils::StorageServiceProperties do
5
+ it "convert an option hash to a service properties xml" do
6
+
7
+ options = {
8
+ "Logging" => {
9
+ "Version" => "1.0",
10
+ "Delete" => "true",
11
+ "Read" => "true",
12
+ "Write" => "true",
13
+ "RetentionPolicy" => {
14
+ "Enabled" => true,
15
+ "Days" => 7
16
+ }
17
+ },
18
+ "Metrics"=> {
19
+ "Version" => "1.0",
20
+ "Enabled" => "true",
21
+ "IncludeAPIs" => "false",
22
+ "RetentionPolicy" => {
23
+ "Enabled" => true,
24
+ "Days" => 7
25
+ }
26
+ }
27
+ }
28
+
29
+ xml = Azure::Core::Utils::StorageServiceProperties.hash_to_xml(options)
30
+
31
+ (xml / "Logging" / "Version").text.must_equal "1.0"
32
+ (xml / "Logging" / "Delete").text.must_equal "true"
33
+ (xml / "Metrics" / "IncludeAPIs").text.must_equal "false"
34
+ (xml / "Metrics" / "RetentionPolicy" / "Enabled").text.must_equal "true"
35
+ (xml / "Metrics" / "RetentionPolicy" / "Days").text.must_equal "7"
36
+ end
37
+
38
+ it "should be able to convert from an xml document string to a hash" do
39
+ xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
40
+ <StorageServiceProperties>
41
+ <Logging>
42
+ <Version>version-number</Version>
43
+ <Delete>true</Delete>
44
+ <Read>true</Read>
45
+ <Write>true</Write>
46
+ <RetentionPolicy>
47
+ <Enabled>true</Enabled>
48
+ <Days>number-of-days</Days>
49
+ </RetentionPolicy>
50
+ </Logging>
51
+ <Metrics>
52
+ <Version>version-number</Version>
53
+ <Enabled>true</Enabled>
54
+ <IncludeAPIs>true</IncludeAPIs>
55
+ <RetentionPolicy>
56
+ <Enabled>true</Enabled>
57
+ <Days>number-of-days</Days>
58
+ </RetentionPolicy>
59
+ </Metrics>
60
+ <DefaultServiceVersion>default-service-version-string</DefaultServiceVersion>
61
+ </StorageServiceProperties>"
62
+
63
+ hash = Azure::Core::Utils::StorageServiceProperties.xml_string_to_hash(xml)
64
+ hash["Logging"]["Read"].must_equal "true"
65
+ end
66
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+ require "azure/error"
3
+
4
+ describe Azure::HTTPError do
5
+ let :http_response do
6
+ double(body: Fixtures[:error], code: 409)
7
+ end
8
+
9
+ subject do
10
+ Azure::HTTPError.new(http_response)
11
+ end
12
+
13
+ it "is an Azure::Error" do
14
+ subject.must_be_kind_of Azure::Error
15
+ end
16
+
17
+ it "lets us see the errors'status code" do
18
+ subject.code.must_equal 409
19
+ end
20
+
21
+ it "lets us see the error's type" do
22
+ subject.type.must_equal "TableAlreadyExists"
23
+ end
24
+
25
+ it "lets us see the error's description" do
26
+ subject.description.must_equal "The table specified already exists."
27
+ end
28
+
29
+ it "generates an error message that wraps both the type and description" do
30
+ subject.message.must_equal "TableAlreadyExists (409): The table specified already exists."
31
+ end
32
+
33
+ it "sets the type to unknown if the response body is not an XML" do
34
+ http_response.body = "\r\nInvalid request\r\n"
35
+
36
+ subject.type.must_equal "Unknown"
37
+ subject.description.must_equal "Invalid request"
38
+ end
39
+ end