gcloud 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +13 -5
  2. data/AUTHENTICATION.md +71 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +10 -15
  5. data/lib/gcloud.rb +30 -0
  6. data/lib/gcloud/backoff.rb +3 -0
  7. data/lib/gcloud/credentials.rb +47 -30
  8. data/lib/gcloud/datastore.rb +246 -15
  9. data/lib/gcloud/datastore/connection.rb +4 -2
  10. data/lib/gcloud/datastore/credentials.rb +3 -1
  11. data/lib/gcloud/datastore/dataset.rb +130 -25
  12. data/lib/gcloud/datastore/dataset/lookup_results.rb +1 -0
  13. data/lib/gcloud/datastore/dataset/query_results.rb +7 -5
  14. data/lib/gcloud/datastore/entity.rb +99 -17
  15. data/lib/gcloud/datastore/errors.rb +13 -2
  16. data/lib/gcloud/datastore/key.rb +133 -2
  17. data/lib/gcloud/datastore/properties.rb +6 -1
  18. data/lib/gcloud/datastore/proto.rb +2 -1
  19. data/lib/gcloud/datastore/query.rb +4 -4
  20. data/lib/gcloud/datastore/transaction.rb +3 -0
  21. data/lib/gcloud/storage.rb +280 -13
  22. data/lib/gcloud/storage/bucket.rb +248 -11
  23. data/lib/gcloud/storage/bucket/acl.rb +631 -4
  24. data/lib/gcloud/storage/bucket/list.rb +1 -0
  25. data/lib/gcloud/storage/connection.rb +1 -0
  26. data/lib/gcloud/storage/credentials.rb +3 -1
  27. data/lib/gcloud/storage/errors.rb +9 -1
  28. data/lib/gcloud/storage/file.rb +231 -6
  29. data/lib/gcloud/storage/file/acl.rb +365 -2
  30. data/lib/gcloud/storage/file/list.rb +1 -0
  31. data/lib/gcloud/storage/file/verifier.rb +1 -0
  32. data/lib/gcloud/storage/project.rb +119 -10
  33. data/lib/gcloud/version.rb +18 -3
  34. metadata +33 -80
  35. data/.gemtest +0 -0
  36. data/.rubocop.yml +0 -17
  37. data/Manifest.txt +0 -66
  38. data/Rakefile +0 -35
  39. data/gcloud.gemspec +0 -63
  40. data/rakelib/console.rake +0 -28
  41. data/rakelib/manifest.rake +0 -24
  42. data/rakelib/proto.rake +0 -17
  43. data/rakelib/rubocop.rake +0 -17
  44. data/rakelib/test.rake +0 -144
  45. data/test/gcloud/datastore/proto/test_cursor.rb +0 -36
  46. data/test/gcloud/datastore/proto/test_direction.rb +0 -60
  47. data/test/gcloud/datastore/proto/test_operator.rb +0 -76
  48. data/test/gcloud/datastore/proto/test_value.rb +0 -231
  49. data/test/gcloud/datastore/test_connection.rb +0 -93
  50. data/test/gcloud/datastore/test_credentials.rb +0 -38
  51. data/test/gcloud/datastore/test_dataset.rb +0 -413
  52. data/test/gcloud/datastore/test_entity.rb +0 -161
  53. data/test/gcloud/datastore/test_entity_exclude.rb +0 -225
  54. data/test/gcloud/datastore/test_key.rb +0 -189
  55. data/test/gcloud/datastore/test_query.rb +0 -271
  56. data/test/gcloud/datastore/test_transaction.rb +0 -121
  57. data/test/gcloud/storage/test_backoff.rb +0 -127
  58. data/test/gcloud/storage/test_bucket.rb +0 -270
  59. data/test/gcloud/storage/test_bucket_acl.rb +0 -253
  60. data/test/gcloud/storage/test_default_acl.rb +0 -256
  61. data/test/gcloud/storage/test_file.rb +0 -221
  62. data/test/gcloud/storage/test_file_acl.rb +0 -367
  63. data/test/gcloud/storage/test_project.rb +0 -180
  64. data/test/gcloud/storage/test_storage.rb +0 -29
  65. data/test/gcloud/storage/test_verifier.rb +0 -62
  66. data/test/gcloud/test_version.rb +0 -8
  67. data/test/helper.rb +0 -91
@@ -1,367 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "helper"
16
- require "json"
17
- require "uri"
18
-
19
- describe Gcloud::Storage::File, :acl, :mock_storage do
20
- # Create a bucket object with the project's mocked connection object
21
- let(:bucket_name) { "bucket" }
22
- let(:bucket) { Gcloud::Storage::Bucket.from_gapi random_bucket_hash(bucket_name),
23
- storage.connection }
24
-
25
- # Create a file object with the project's mocked connection object
26
- let(:file_name) { "file.ext" }
27
- let(:file) { Gcloud::Storage::File.from_gapi random_file_hash(bucket_name, file_name),
28
- storage.connection }
29
-
30
- it "retrieves the ACL" do
31
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
32
- URI(env.url).query.must_be :nil?
33
- [200, {"Content-Type"=>"application/json"},
34
- random_file_hash(bucket_name, file_name).to_json]
35
- end
36
-
37
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
38
- [200, {"Content-Type"=>"application/json"},
39
- random_file_acl_hash(bucket_name, file_name).to_json]
40
- end
41
-
42
- file = bucket.find_file file_name
43
- file.name.must_equal file_name
44
- file.acl.owners.wont_be :empty?
45
- file.acl.writers.must_be :empty?
46
- file.acl.readers.wont_be :empty?
47
- end
48
-
49
- it "adds to the ACL without generation" do
50
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
51
- [200, {"Content-Type"=>"application/json"},
52
- random_file_hash(bucket_name, file_name).to_json]
53
- end
54
-
55
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
56
- [200, {"Content-Type"=>"application/json"},
57
- random_file_acl_hash(bucket_name, file_name).to_json]
58
- end
59
-
60
- file = bucket.find_file file_name
61
- file.name.must_equal file_name
62
- file.acl.owners.wont_be :empty?
63
- file.acl.writers.must_be :empty?
64
- file.acl.readers.wont_be :empty?
65
-
66
- writer_entity = "user-user@example.net"
67
- writer_acl = {
68
- "kind" => "storage#objectAccessControl",
69
- "id" => "#{bucket_name}/#{file_name}/123/user-12345678901234567890",
70
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/#{writer_entity}",
71
- "bucket" => "#{bucket_name}",
72
- "object" => "#{file_name}",
73
- "generation" => "123",
74
- "entity" => writer_entity,
75
- "role" => "WRITER",
76
- "entityId" => "12345678901234567890",
77
- "etag" => "abcDEF123="
78
- }
79
-
80
- mock_connection.post "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
81
- URI(env.url).query.must_be :nil?
82
- [200, {"Content-Type"=>"application/json"},
83
- writer_acl.to_json]
84
- end
85
-
86
- file.acl.add_writer writer_entity
87
- file.acl.owners.wont_be :empty?
88
- file.acl.writers.wont_be :empty?
89
- file.acl.readers.wont_be :empty?
90
- file.acl.writers.must_include writer_entity
91
- end
92
-
93
- it "adds to the ACL with generation" do
94
- generation = "123"
95
-
96
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
97
- [200, {"Content-Type"=>"application/json"},
98
- random_file_hash(bucket_name, file_name).to_json]
99
- end
100
-
101
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
102
- [200, {"Content-Type"=>"application/json"},
103
- random_file_acl_hash(bucket_name, file_name).to_json]
104
- end
105
-
106
- file = bucket.find_file file_name
107
- file.name.must_equal file_name
108
- file.acl.owners.wont_be :empty?
109
- file.acl.writers.must_be :empty?
110
- file.acl.readers.wont_be :empty?
111
-
112
- writer_entity = "user-user@example.net"
113
- writer_acl = {
114
- "kind" => "storage#objectAccessControl",
115
- "id" => "#{bucket_name}/#{file_name}/123/user-12345678901234567890",
116
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/#{writer_entity}",
117
- "bucket" => "#{bucket_name}",
118
- "object" => "#{file_name}",
119
- "generation" => "123",
120
- "entity" => writer_entity,
121
- "role" => "WRITER",
122
- "entityId" => "12345678901234567890",
123
- "etag" => "abcDEF123="
124
- }
125
-
126
- mock_connection.post "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
127
- URI(env.url).query.must_equal "generation=#{generation}"
128
- [200, {"Content-Type"=>"application/json"},
129
- writer_acl.to_json]
130
- end
131
-
132
- file.acl.add_writer writer_entity, generation: generation
133
- file.acl.owners.wont_be :empty?
134
- file.acl.writers.wont_be :empty?
135
- file.acl.readers.wont_be :empty?
136
- file.acl.writers.must_include writer_entity
137
- end
138
-
139
- it "removes from the ACL without generation" do
140
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
141
- [200, {"Content-Type"=>"application/json"},
142
- random_file_hash(bucket_name, file_name).to_json]
143
- end
144
-
145
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
146
- [200, {"Content-Type"=>"application/json"},
147
- random_file_acl_hash(bucket_name, file_name).to_json]
148
- end
149
-
150
- file = bucket.find_file file_name
151
- file.name.must_equal file_name
152
- file.acl.owners.wont_be :empty?
153
- file.acl.writers.must_be :empty?
154
- file.acl.readers.wont_be :empty?
155
-
156
- reader_entity = file.acl.readers.first
157
-
158
- mock_connection.delete "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/#{reader_entity}" do |env|
159
- URI(env.url).query.must_be :nil?
160
- [200, {"Content-Type"=>"application/json"}, ""]
161
- end
162
-
163
- file.acl.delete reader_entity
164
-
165
- file.acl.owners.wont_be :empty?
166
- file.acl.writers.must_be :empty?
167
- file.acl.readers.must_be :empty?
168
- end
169
-
170
- it "removes from the ACL with generation" do
171
- generation = "123"
172
-
173
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
174
- [200, {"Content-Type"=>"application/json"},
175
- random_file_hash(bucket_name, file_name).to_json]
176
- end
177
-
178
- mock_connection.get "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl" do |env|
179
- [200, {"Content-Type"=>"application/json"},
180
- random_file_acl_hash(bucket_name, file_name).to_json]
181
- end
182
-
183
- file = bucket.find_file file_name
184
- file.name.must_equal file_name
185
- file.acl.owners.wont_be :empty?
186
- file.acl.writers.must_be :empty?
187
- file.acl.readers.wont_be :empty?
188
-
189
- reader_entity = file.acl.readers.first
190
-
191
- mock_connection.delete "/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/#{reader_entity}" do |env|
192
- URI(env.url).query.must_equal "generation=#{generation}"
193
- [200, {"Content-Type"=>"application/json"}, ""]
194
- end
195
-
196
- file.acl.delete reader_entity, generation: generation
197
-
198
- file.acl.owners.wont_be :empty?
199
- file.acl.writers.must_be :empty?
200
- file.acl.readers.must_be :empty?
201
- end
202
-
203
- it "sets the predefined ACL rule authenticatedRead" do
204
- predefined_acl_update "authenticatedRead" do |acl|
205
- acl.authenticatedRead!
206
- end
207
- end
208
-
209
- it "sets the predefined ACL rule auth" do
210
- predefined_acl_update "authenticatedRead" do |acl|
211
- acl.auth!
212
- end
213
- end
214
-
215
- it "sets the predefined ACL rule auth_read" do
216
- predefined_acl_update "authenticatedRead" do |acl|
217
- acl.auth_read!
218
- end
219
- end
220
-
221
- it "sets the predefined ACL rule authenticated" do
222
- predefined_acl_update "authenticatedRead" do |acl|
223
- acl.authenticated!
224
- end
225
- end
226
-
227
- it "sets the predefined ACL rule authenticated_read" do
228
- predefined_acl_update "authenticatedRead" do |acl|
229
- acl.authenticated_read!
230
- end
231
- end
232
-
233
- it "sets the predefined ACL rule bucketOwnerFullControl" do
234
- predefined_acl_update "bucketOwnerFullControl" do |acl|
235
- acl.bucketOwnerFullControl!
236
- end
237
- end
238
-
239
- it "sets the predefined ACL rule owner_full" do
240
- predefined_acl_update "bucketOwnerFullControl" do |acl|
241
- acl.owner_full!
242
- end
243
- end
244
-
245
- it "sets the predefined ACL rule bucketOwnerRead" do
246
- predefined_acl_update "bucketOwnerRead" do |acl|
247
- acl.bucketOwnerRead!
248
- end
249
- end
250
-
251
- it "sets the predefined ACL rule owner_read" do
252
- predefined_acl_update "bucketOwnerRead" do |acl|
253
- acl.owner_read!
254
- end
255
- end
256
-
257
- it "sets the predefined ACL rule private" do
258
- predefined_acl_update "private" do |acl|
259
- acl.private!
260
- end
261
- end
262
-
263
- it "sets the predefined ACL rule projectPrivate" do
264
- predefined_acl_update "projectPrivate" do |acl|
265
- acl.projectPrivate!
266
- end
267
- end
268
-
269
- it "sets the predefined ACL rule project_private" do
270
- predefined_acl_update "projectPrivate" do |acl|
271
- acl.project_private!
272
- end
273
- end
274
-
275
- it "sets the predefined ACL rule publicRead" do
276
- predefined_acl_update "publicRead" do |acl|
277
- acl.publicRead!
278
- end
279
- end
280
-
281
- it "sets the predefined ACL rule public" do
282
- predefined_acl_update "publicRead" do |acl|
283
- acl.public!
284
- end
285
- end
286
-
287
- it "sets the predefined ACL rule public_read" do
288
- predefined_acl_update "publicRead" do |acl|
289
- acl.public_read!
290
- end
291
- end
292
-
293
- def predefined_acl_update acl_role
294
- mock_connection.patch "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
295
- env.params["predefinedAcl"].must_equal acl_role
296
- [200, {"Content-Type"=>"application/json"},
297
- random_file_hash(bucket_name, file_name).to_json]
298
- end
299
-
300
- yield file.acl
301
- end
302
-
303
- def random_file_acl_hash bucket_name, file_name
304
- {
305
- "kind" => "storage#objectAccessControls",
306
- "items" => [
307
- {
308
- "kind" => "storage#objectAccessControl",
309
- "id" => "#{bucket_name}/#{file_name}/123/project-owners-1234567890",
310
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/project-owners-1234567890",
311
- "bucket" => "#{bucket_name}",
312
- "object" => "#{file_name}",
313
- "generation" => "123",
314
- "entity" => "project-owners-1234567890",
315
- "role" => "OWNER",
316
- "projectTeam" => {
317
- "projectNumber" => "1234567890",
318
- "team" => "owners"
319
- },
320
- "etag" => "abcDEF123="
321
- },
322
- {
323
- "kind" => "storage#objectAccessControl",
324
- "id" => "#{bucket_name}/#{file_name}/123/project-editors-1234567890",
325
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/project-editors-1234567890",
326
- "bucket" => "#{bucket_name}",
327
- "object" => "#{file_name}",
328
- "generation" => "123",
329
- "entity" => "project-editors-1234567890",
330
- "role" => "OWNER",
331
- "projectTeam" => {
332
- "projectNumber" => "1234567890",
333
- "team" => "editors"
334
- },
335
- "etag" => "abcDEF123="
336
- },
337
- {
338
- "kind" => "storage#objectAccessControl",
339
- "id" => "#{bucket_name}/#{file_name}/123/project-viewers-1234567890",
340
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/project-viewers-1234567890",
341
- "bucket" => "#{bucket_name}",
342
- "object" => "#{file_name}",
343
- "generation" => "123",
344
- "entity" => "project-viewers-1234567890",
345
- "role" => "READER",
346
- "projectTeam" => {
347
- "projectNumber" => "1234567890",
348
- "team" => "viewers"
349
- },
350
- "etag" => "abcDEF123="
351
- },
352
- {
353
- "kind" => "storage#objectAccessControl",
354
- "id" => "#{bucket_name}/#{file_name}/123/user-12345678901234567890",
355
- "selfLink" => "https://www.googleapis.com/storage/v1/b/#{bucket_name}/o/#{file_name}/acl/user-12345678901234567890",
356
- "bucket" => "#{bucket_name}",
357
- "object" => "#{file_name}",
358
- "generation" => "123",
359
- "entity" => "user-12345678901234567890",
360
- "role" => "OWNER",
361
- "entityId" => "12345678901234567890",
362
- "etag" => "abcDEF123="
363
- }
364
- ]
365
- }
366
- end
367
- end
@@ -1,180 +0,0 @@
1
- # Copyright 2014 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "helper"
16
- require "json"
17
-
18
- describe Gcloud::Storage::Project, :mock_storage do
19
- it "creates a bucket" do
20
- new_bucket_name = "new-bucket-#{Time.now.to_i}"
21
-
22
- mock_connection.post "/storage/v1/b?project=#{project}" do |env|
23
- JSON.parse(env.body)["name"].must_equal new_bucket_name
24
- env.params.wont_include "predefinedAcl"
25
- env.params.wont_include "predefinedDefaultObjectAcl"
26
- [200, {"Content-Type"=>"application/json"},
27
- create_bucket_json]
28
- end
29
-
30
- storage.create_bucket new_bucket_name
31
- end
32
-
33
- it "creates a bucket with predefined acl" do
34
- new_bucket_name = "new-bucket-#{Time.now.to_i}"
35
-
36
- mock_connection.post "/storage/v1/b?project=#{project}" do |env|
37
- env.params.must_include "predefinedAcl"
38
- env.params["predefinedAcl"].must_equal "private"
39
- env.params.wont_include "predefinedDefaultObjectAcl"
40
- JSON.parse(env.body)["name"].must_equal new_bucket_name
41
- [200, {"Content-Type"=>"application/json"},
42
- create_bucket_json]
43
- end
44
-
45
- storage.create_bucket new_bucket_name, acl: "private"
46
- end
47
-
48
- it "creates a bucket with predefined acl alias" do
49
- new_bucket_name = "new-bucket-#{Time.now.to_i}"
50
-
51
- mock_connection.post "/storage/v1/b?project=#{project}" do |env|
52
- env.params.must_include "predefinedAcl"
53
- env.params["predefinedAcl"].must_equal "publicRead"
54
- env.params.wont_include "predefinedDefaultObjectAcl"
55
- JSON.parse(env.body)["name"].must_equal new_bucket_name
56
- [200, {"Content-Type"=>"application/json"},
57
- create_bucket_json]
58
- end
59
-
60
- storage.create_bucket new_bucket_name, acl: :public
61
- end
62
-
63
- it "creates a bucket with predefined default acl" do
64
- new_bucket_name = "new-bucket-#{Time.now.to_i}"
65
-
66
- mock_connection.post "/storage/v1/b?project=#{project}" do |env|
67
- env.params.wont_include "predefinedAcl"
68
- env.params.must_include "predefinedDefaultObjectAcl"
69
- env.params["predefinedDefaultObjectAcl"].must_equal "private"
70
- JSON.parse(env.body)["name"].must_equal new_bucket_name
71
- [200, {"Content-Type"=>"application/json"},
72
- create_bucket_json]
73
- end
74
-
75
- storage.create_bucket new_bucket_name, default_acl: "private"
76
- end
77
-
78
- it "creates a bucket with predefined default acl" do
79
- new_bucket_name = "new-bucket-#{Time.now.to_i}"
80
-
81
- mock_connection.post "/storage/v1/b?project=#{project}" do |env|
82
- env.params.wont_include "predefinedAcl"
83
- env.params.must_include "predefinedDefaultObjectAcl"
84
- env.params["predefinedDefaultObjectAcl"].must_equal "publicRead"
85
- JSON.parse(env.body)["name"].must_equal new_bucket_name
86
- [200, {"Content-Type"=>"application/json"},
87
- create_bucket_json]
88
- end
89
-
90
- storage.create_bucket new_bucket_name, default_acl: :public
91
- end
92
-
93
- it "lists buckets" do
94
- num_buckets = 3
95
- mock_connection.get "/storage/v1/b?project=#{project}" do |env|
96
- [200, {"Content-Type"=>"application/json"},
97
- list_buckets_json(num_buckets)]
98
- end
99
-
100
- buckets = storage.buckets
101
- buckets.size.must_equal num_buckets
102
- end
103
-
104
- it "paginates buckets" do
105
- mock_connection.get "/storage/v1/b?project=#{project}" do |env|
106
- env.params.wont_include "pageToken"
107
- [200, {"Content-Type"=>"application/json"},
108
- list_buckets_json(3, "next_page_token")]
109
- end
110
- mock_connection.get "/storage/v1/b?project=#{project}" do |env|
111
- env.params.must_include "pageToken"
112
- env.params["pageToken"].must_equal "next_page_token"
113
- [200, {"Content-Type"=>"application/json"},
114
- list_buckets_json(2)]
115
- end
116
-
117
- first_buckets = storage.buckets
118
- first_buckets.count.must_equal 3
119
- first_buckets.token.wont_be :nil?
120
- first_buckets.token.must_equal "next_page_token"
121
-
122
- second_buckets = storage.buckets token: first_buckets.token
123
- second_buckets.count.must_equal 2
124
- second_buckets.token.must_be :nil?
125
- end
126
-
127
- it "paginates buckets with max set" do
128
- mock_connection.get "/storage/v1/b?project=#{project}" do |env|
129
- env.params.must_include "maxResults"
130
- env.params["maxResults"].must_equal "3"
131
- [200, {"Content-Type"=>"application/json"},
132
- list_buckets_json(3, "next_page_token")]
133
- end
134
-
135
- subs = storage.buckets max: 3
136
- subs.count.must_equal 3
137
- subs.token.wont_be :nil?
138
- subs.token.must_equal "next_page_token"
139
- end
140
-
141
- it "paginates buckets without max set" do
142
- mock_connection.get "/storage/v1/b?project=#{project}" do |env|
143
- env.params.wont_include "maxResults"
144
- [200, {"Content-Type"=>"application/json"},
145
- list_buckets_json(3, "next_page_token")]
146
- end
147
-
148
- subs = storage.buckets
149
- subs.count.must_equal 3
150
- subs.token.wont_be :nil?
151
- subs.token.must_equal "next_page_token"
152
- end
153
-
154
- it "finds a bucket" do
155
- bucket_name = "found-bucket"
156
-
157
- mock_connection.get "/storage/v1/b/#{bucket_name}" do |env|
158
- [200, {"Content-Type"=>"application/json"},
159
- find_bucket_json(bucket_name)]
160
- end
161
-
162
- bucket = storage.find_bucket bucket_name
163
- bucket.name.must_equal bucket_name
164
- end
165
-
166
- def create_bucket_json
167
- random_bucket_hash.to_json
168
- end
169
-
170
- def find_bucket_json name = nil
171
- random_bucket_hash(name).to_json
172
- end
173
-
174
- def list_buckets_json count = 2, token = nil
175
- buckets = count.times.map { random_bucket_hash }
176
- hash = {"kind"=>"storage#buckets", "items"=>buckets}
177
- hash["nextPageToken"] = token unless token.nil?
178
- hash.to_json
179
- end
180
- end