gcloud 0.1.0 → 0.1.1
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.
- checksums.yaml +13 -5
- data/AUTHENTICATION.md +71 -0
- data/CHANGELOG.md +5 -0
- data/README.md +10 -15
- data/lib/gcloud.rb +30 -0
- data/lib/gcloud/backoff.rb +3 -0
- data/lib/gcloud/credentials.rb +47 -30
- data/lib/gcloud/datastore.rb +246 -15
- data/lib/gcloud/datastore/connection.rb +4 -2
- data/lib/gcloud/datastore/credentials.rb +3 -1
- data/lib/gcloud/datastore/dataset.rb +130 -25
- data/lib/gcloud/datastore/dataset/lookup_results.rb +1 -0
- data/lib/gcloud/datastore/dataset/query_results.rb +7 -5
- data/lib/gcloud/datastore/entity.rb +99 -17
- data/lib/gcloud/datastore/errors.rb +13 -2
- data/lib/gcloud/datastore/key.rb +133 -2
- data/lib/gcloud/datastore/properties.rb +6 -1
- data/lib/gcloud/datastore/proto.rb +2 -1
- data/lib/gcloud/datastore/query.rb +4 -4
- data/lib/gcloud/datastore/transaction.rb +3 -0
- data/lib/gcloud/storage.rb +280 -13
- data/lib/gcloud/storage/bucket.rb +248 -11
- data/lib/gcloud/storage/bucket/acl.rb +631 -4
- data/lib/gcloud/storage/bucket/list.rb +1 -0
- data/lib/gcloud/storage/connection.rb +1 -0
- data/lib/gcloud/storage/credentials.rb +3 -1
- data/lib/gcloud/storage/errors.rb +9 -1
- data/lib/gcloud/storage/file.rb +231 -6
- data/lib/gcloud/storage/file/acl.rb +365 -2
- data/lib/gcloud/storage/file/list.rb +1 -0
- data/lib/gcloud/storage/file/verifier.rb +1 -0
- data/lib/gcloud/storage/project.rb +119 -10
- data/lib/gcloud/version.rb +18 -3
- metadata +33 -80
- data/.gemtest +0 -0
- data/.rubocop.yml +0 -17
- data/Manifest.txt +0 -66
- data/Rakefile +0 -35
- data/gcloud.gemspec +0 -63
- data/rakelib/console.rake +0 -28
- data/rakelib/manifest.rake +0 -24
- data/rakelib/proto.rake +0 -17
- data/rakelib/rubocop.rake +0 -17
- data/rakelib/test.rake +0 -144
- data/test/gcloud/datastore/proto/test_cursor.rb +0 -36
- data/test/gcloud/datastore/proto/test_direction.rb +0 -60
- data/test/gcloud/datastore/proto/test_operator.rb +0 -76
- data/test/gcloud/datastore/proto/test_value.rb +0 -231
- data/test/gcloud/datastore/test_connection.rb +0 -93
- data/test/gcloud/datastore/test_credentials.rb +0 -38
- data/test/gcloud/datastore/test_dataset.rb +0 -413
- data/test/gcloud/datastore/test_entity.rb +0 -161
- data/test/gcloud/datastore/test_entity_exclude.rb +0 -225
- data/test/gcloud/datastore/test_key.rb +0 -189
- data/test/gcloud/datastore/test_query.rb +0 -271
- data/test/gcloud/datastore/test_transaction.rb +0 -121
- data/test/gcloud/storage/test_backoff.rb +0 -127
- data/test/gcloud/storage/test_bucket.rb +0 -270
- data/test/gcloud/storage/test_bucket_acl.rb +0 -253
- data/test/gcloud/storage/test_default_acl.rb +0 -256
- data/test/gcloud/storage/test_file.rb +0 -221
- data/test/gcloud/storage/test_file_acl.rb +0 -367
- data/test/gcloud/storage/test_project.rb +0 -180
- data/test/gcloud/storage/test_storage.rb +0 -29
- data/test/gcloud/storage/test_verifier.rb +0 -62
- data/test/gcloud/test_version.rb +0 -8
- data/test/helper.rb +0 -91
@@ -1,161 +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 "gcloud/datastore"
|
17
|
-
|
18
|
-
describe Gcloud::Datastore::Entity do
|
19
|
-
|
20
|
-
let(:entity) do
|
21
|
-
Gcloud::Datastore::Entity.new.tap do |ent|
|
22
|
-
ent.key = Gcloud::Datastore::Key.new "User", "username"
|
23
|
-
ent["name"] = "User McUser"
|
24
|
-
ent["email"] = "user@example.net"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "creates instances with .new" do
|
29
|
-
# Calling entity here creates by calling new
|
30
|
-
entity.wont_be :nil?
|
31
|
-
entity.properties["name"].must_equal "User McUser"
|
32
|
-
entity.properties["email"].must_equal "user@example.net"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns a correct protocol buffer object" do
|
36
|
-
proto = entity.to_proto
|
37
|
-
|
38
|
-
# Key values
|
39
|
-
proto.key.path_element.count.must_equal 1
|
40
|
-
proto.key.path_element.last.kind.must_equal "User"
|
41
|
-
proto.key.path_element.last.id.must_be :nil?
|
42
|
-
proto.key.path_element.last.name.must_equal "username"
|
43
|
-
|
44
|
-
# Property values
|
45
|
-
proto.property.count.must_equal 2
|
46
|
-
proto.property.find { |p| p.name == "name" }.value.string_value.must_equal entity["name"]
|
47
|
-
proto.property.find { |p| p.name == "email" }.value.string_value.must_equal entity["email"]
|
48
|
-
end
|
49
|
-
|
50
|
-
it "can be created with a protocol buffer object" do
|
51
|
-
proto = Gcloud::Datastore::Proto::Entity.new
|
52
|
-
proto.key = Gcloud::Datastore::Proto::Key.new
|
53
|
-
proto.key.path_element = [Gcloud::Datastore::Proto::Key::PathElement.new]
|
54
|
-
proto.key.path_element.first.kind = "User"
|
55
|
-
proto.key.path_element.first.id = 123456
|
56
|
-
proto.property = [Gcloud::Datastore::Proto::Property.new,
|
57
|
-
Gcloud::Datastore::Proto::Property.new]
|
58
|
-
proto.property.first.name = "name"
|
59
|
-
proto.property.first.value = Gcloud::Datastore::Proto.to_proto_value "User McNumber"
|
60
|
-
proto.property.last.name = "email"
|
61
|
-
proto.property.last.value = Gcloud::Datastore::Proto.to_proto_value "number@example.net"
|
62
|
-
|
63
|
-
entity_from_proto = Gcloud::Datastore::Entity.from_proto proto
|
64
|
-
|
65
|
-
entity_from_proto.key.kind.must_equal "User"
|
66
|
-
entity_from_proto.key.id.must_equal 123456
|
67
|
-
entity_from_proto.key.name.must_be :nil?
|
68
|
-
entity_from_proto.properties["name"].must_equal "User McNumber"
|
69
|
-
entity_from_proto.properties["email"].must_equal "number@example.net"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "can store other entities as properties" do
|
73
|
-
task1 = Gcloud::Datastore::Entity.new.tap do |t|
|
74
|
-
t.key = Gcloud::Datastore::Key.new "Task", 1111
|
75
|
-
t["description"] = "can persist entities"
|
76
|
-
t["completed"] = true
|
77
|
-
end
|
78
|
-
task2 = Gcloud::Datastore::Entity.new.tap do |t|
|
79
|
-
t.key = Gcloud::Datastore::Key.new "Task", 2222
|
80
|
-
t["description"] = "can persist lists"
|
81
|
-
t["completed"] = true
|
82
|
-
end
|
83
|
-
entity["tasks"] = [task1, task2]
|
84
|
-
|
85
|
-
proto = entity.to_proto
|
86
|
-
|
87
|
-
task_property = proto.property.last
|
88
|
-
task_property.name.must_equal "tasks"
|
89
|
-
task_property.value.list_value.wont_be :nil?
|
90
|
-
task_property.value.list_value.count.must_equal 2
|
91
|
-
proto_task_1 = task_property.value.list_value.first
|
92
|
-
proto_task_2 = task_property.value.list_value.last
|
93
|
-
proto_task_1.wont_be :nil?
|
94
|
-
proto_task_2.wont_be :nil?
|
95
|
-
proto_task_1.entity_value.wont_be :nil?
|
96
|
-
proto_task_2.entity_value.wont_be :nil?
|
97
|
-
proto_task_1.entity_value.property.find { |p| p.name == "description" }.value.string_value.must_equal "can persist entities"
|
98
|
-
proto_task_2.entity_value.property.find { |p| p.name == "description" }.value.string_value.must_equal "can persist lists"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "can store keys as properties" do
|
102
|
-
list = Gcloud::Datastore::Entity.new.tap do |t|
|
103
|
-
t.key = Gcloud::Datastore::Key.new "List", 1111
|
104
|
-
t["description"] = "can persist keys"
|
105
|
-
end
|
106
|
-
key1 = Gcloud::Datastore::Key.new "Task", 1111
|
107
|
-
|
108
|
-
list["head"] = key1
|
109
|
-
|
110
|
-
# Do this multiple times to make sure the call to Key.from_proto
|
111
|
-
# isn't modifying the original key stored in the entity's property.
|
112
|
-
5.times do
|
113
|
-
assert_equal key1.path, list["head"].path
|
114
|
-
end
|
115
|
-
|
116
|
-
proto = list.to_proto
|
117
|
-
|
118
|
-
key_property = proto.property.last
|
119
|
-
key_property.name.must_equal "head"
|
120
|
-
|
121
|
-
key_value = key_property.value.key_value
|
122
|
-
key_value.wont_be :nil?
|
123
|
-
key_value.path_element.first.kind.must_equal key1.kind
|
124
|
-
key_value.path_element.first.name.must_equal key1.name
|
125
|
-
key_value.path_element.first.id.must_equal key1.id
|
126
|
-
end
|
127
|
-
|
128
|
-
it "raises when setting an unsupported property type" do
|
129
|
-
error = assert_raises Gcloud::Datastore::PropertyError do
|
130
|
-
entity["thing"] = OpenStruct.new
|
131
|
-
end
|
132
|
-
error.message.must_equal "A property of type OpenStruct is not supported."
|
133
|
-
end
|
134
|
-
|
135
|
-
it "raises when setting a key when persisted" do
|
136
|
-
proto = Gcloud::Datastore::Proto::Entity.new
|
137
|
-
proto.key = Gcloud::Datastore::Proto::Key.new
|
138
|
-
proto.key.path_element = [Gcloud::Datastore::Proto::Key::PathElement.new]
|
139
|
-
proto.key.path_element.first.kind = "User"
|
140
|
-
proto.key.path_element.first.id = 123456
|
141
|
-
proto.property = [Gcloud::Datastore::Proto::Property.new,
|
142
|
-
Gcloud::Datastore::Proto::Property.new]
|
143
|
-
proto.property.first.name = "name"
|
144
|
-
proto.property.first.value = Gcloud::Datastore::Proto.to_proto_value "User McNumber"
|
145
|
-
proto.property.last.name = "email"
|
146
|
-
proto.property.last.value = Gcloud::Datastore::Proto.to_proto_value "number@example.net"
|
147
|
-
|
148
|
-
entity_from_proto = Gcloud::Datastore::Entity.from_proto proto
|
149
|
-
|
150
|
-
entity_from_proto.must_be :persisted?
|
151
|
-
entity_from_proto.key.must_be :frozen?
|
152
|
-
|
153
|
-
assert_raises RuntimeError do
|
154
|
-
entity_from_proto.key = Gcloud::Datastore::Key.new "User", 456789
|
155
|
-
end
|
156
|
-
|
157
|
-
assert_raises RuntimeError do
|
158
|
-
entity_from_proto.key.id = 456789
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
@@ -1,225 +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 "gcloud/datastore"
|
17
|
-
|
18
|
-
describe Gcloud::Datastore::Entity, :exclude_from_indexes do
|
19
|
-
|
20
|
-
let(:entity) do
|
21
|
-
Gcloud::Datastore::Entity.new.tap do |ent|
|
22
|
-
ent.key = Gcloud::Datastore::Key.new "User", "username"
|
23
|
-
ent["name"] = "User McUser"
|
24
|
-
ent["email"] = "user@example.net"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't exclude from indexes by default" do
|
29
|
-
refute entity.exclude_from_indexes?("name")
|
30
|
-
refute entity.exclude_from_indexes?("email")
|
31
|
-
|
32
|
-
proto = entity.to_proto
|
33
|
-
|
34
|
-
assert proto.property.find { |p| p.name == "name" }.value.indexed.must_equal true
|
35
|
-
assert proto.property.find { |p| p.name == "email" }.value.indexed.must_equal true
|
36
|
-
end
|
37
|
-
|
38
|
-
it "excludes when setting a boolean" do
|
39
|
-
entity["age"] = 21
|
40
|
-
entity.exclude_from_indexes! "age", true
|
41
|
-
|
42
|
-
entity.exclude_from_indexes?("age").must_equal true
|
43
|
-
|
44
|
-
proto = entity.to_proto
|
45
|
-
|
46
|
-
proto.property.find { |p| p.name == "age" }.value.indexed.must_equal false
|
47
|
-
end
|
48
|
-
|
49
|
-
it "excludes when setting a Proc" do
|
50
|
-
entity["age"] = 21
|
51
|
-
entity.exclude_from_indexes! "age" do |age|
|
52
|
-
age > 18
|
53
|
-
end
|
54
|
-
|
55
|
-
entity.exclude_from_indexes?("age").must_equal true
|
56
|
-
|
57
|
-
proto = entity.to_proto
|
58
|
-
|
59
|
-
proto.property.find { |p| p.name == "age" }.value.indexed.must_equal false
|
60
|
-
|
61
|
-
# And now the inverse, the Proc evaluates to false
|
62
|
-
|
63
|
-
entity.exclude_from_indexes! "age" do |age|
|
64
|
-
age < 18
|
65
|
-
end
|
66
|
-
|
67
|
-
entity.exclude_from_indexes?("age").must_equal false
|
68
|
-
|
69
|
-
proto = entity.to_proto
|
70
|
-
|
71
|
-
proto.property.find { |p| p.name == "age" }.value.indexed.must_equal true
|
72
|
-
end
|
73
|
-
|
74
|
-
it "excludes when setting an Array on a non array value" do
|
75
|
-
entity["age"] = 21
|
76
|
-
entity.exclude_from_indexes! "age", [true, false, true, false]
|
77
|
-
|
78
|
-
entity.exclude_from_indexes?("age").must_equal true
|
79
|
-
|
80
|
-
proto = entity.to_proto
|
81
|
-
|
82
|
-
proto.property.find { |p| p.name == "age" }.value.indexed.must_equal false
|
83
|
-
|
84
|
-
# And now the inverse, the first value is false
|
85
|
-
|
86
|
-
entity.exclude_from_indexes! "age", [false, true, false, true]
|
87
|
-
|
88
|
-
entity.exclude_from_indexes?("age").must_equal false
|
89
|
-
|
90
|
-
proto = entity.to_proto
|
91
|
-
|
92
|
-
proto.property.find { |p| p.name == "age" }.value.indexed.must_equal true
|
93
|
-
end
|
94
|
-
|
95
|
-
describe Array do
|
96
|
-
it "doesn't exclude Array values from indexes by default" do
|
97
|
-
entity["tags"] = ["ruby", "code"]
|
98
|
-
|
99
|
-
entity.exclude_from_indexes?("tags").must_equal [false, false]
|
100
|
-
|
101
|
-
proto = entity.to_proto
|
102
|
-
|
103
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
104
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
105
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [true, true]
|
106
|
-
end
|
107
|
-
|
108
|
-
it "excludes an Array when setting a boolean" do
|
109
|
-
entity["tags"] = ["ruby", "code"]
|
110
|
-
entity.exclude_from_indexes! "tags", true
|
111
|
-
|
112
|
-
entity.exclude_from_indexes?("tags").must_equal [true, true]
|
113
|
-
|
114
|
-
proto = entity.to_proto
|
115
|
-
|
116
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
117
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
118
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, false]
|
119
|
-
end
|
120
|
-
|
121
|
-
it "excludes an Array when setting a Proc" do
|
122
|
-
entity["tags"] = ["ruby", "code"]
|
123
|
-
entity.exclude_from_indexes! "tags" do |tag|
|
124
|
-
tag =~ /r/
|
125
|
-
end
|
126
|
-
|
127
|
-
entity.exclude_from_indexes?("tags").must_equal [true, false]
|
128
|
-
|
129
|
-
proto = entity.to_proto
|
130
|
-
|
131
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
132
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
133
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, true]
|
134
|
-
|
135
|
-
# And now the inverse, the Proc evaluates to false
|
136
|
-
|
137
|
-
entity["tags"] = ["ruby", "code"]
|
138
|
-
entity.exclude_from_indexes! "tags" do |tag|
|
139
|
-
tag =~ /c/
|
140
|
-
end
|
141
|
-
|
142
|
-
entity.exclude_from_indexes?("tags").must_equal [false, true]
|
143
|
-
|
144
|
-
proto = entity.to_proto
|
145
|
-
|
146
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
147
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
148
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [true, false]
|
149
|
-
end
|
150
|
-
|
151
|
-
it "excludes an Array when setting an Array" do
|
152
|
-
entity["tags"] = ["ruby", "code"]
|
153
|
-
entity.exclude_from_indexes! "tags", [true, false]
|
154
|
-
|
155
|
-
entity.exclude_from_indexes?("tags").must_equal [true, false]
|
156
|
-
|
157
|
-
proto = entity.to_proto
|
158
|
-
|
159
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
160
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
161
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, true]
|
162
|
-
end
|
163
|
-
|
164
|
-
it "excludes an Array when setting an Array that is too small" do
|
165
|
-
entity["tags"] = ["ruby", "code", "google", "cloud"]
|
166
|
-
entity.exclude_from_indexes! "tags", [true, false]
|
167
|
-
|
168
|
-
# the default is to not exclude when the array is too small
|
169
|
-
entity.exclude_from_indexes?("tags").must_equal [true, false, false, false]
|
170
|
-
|
171
|
-
proto = entity.to_proto
|
172
|
-
|
173
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
174
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
175
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, true, true, true]
|
176
|
-
end
|
177
|
-
|
178
|
-
it "excludes an Array when setting an Array that is too big" do
|
179
|
-
entity["tags"] = ["ruby", "code"]
|
180
|
-
entity.exclude_from_indexes! "tags", [true, false, true, false, true, false]
|
181
|
-
|
182
|
-
entity.exclude_from_indexes?("tags").must_equal [true, false]
|
183
|
-
|
184
|
-
proto = entity.to_proto
|
185
|
-
|
186
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
187
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
188
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, true]
|
189
|
-
|
190
|
-
# Now add to the entity and get the previously stored exclude values
|
191
|
-
|
192
|
-
entity["tags"] = ["ruby", "code", "google", "cloud"]
|
193
|
-
|
194
|
-
entity.exclude_from_indexes?("tags").must_equal [true, false, true, false]
|
195
|
-
|
196
|
-
proto = entity.to_proto
|
197
|
-
|
198
|
-
tag_proto = proto.property.find { |p| p.name == "tags" }.value
|
199
|
-
tag_proto.indexed.must_be :nil? # list values must always be unset
|
200
|
-
tag_proto.list_value.map { |value| value.indexed }.must_equal [false, true, false, true]
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "Edge Cases" do
|
205
|
-
it "recalculates when changing from a single value to an array" do
|
206
|
-
entity["tags"] = "ruby"
|
207
|
-
|
208
|
-
entity.exclude_from_indexes?("tags").must_equal false
|
209
|
-
|
210
|
-
entity.exclude_from_indexes! "tags", true
|
211
|
-
|
212
|
-
entity.exclude_from_indexes?("tags").must_equal true
|
213
|
-
|
214
|
-
entity["tags"] = ["ruby", "code"]
|
215
|
-
|
216
|
-
entity.exclude_from_indexes?("tags").must_equal [true, true]
|
217
|
-
|
218
|
-
entity.exclude_from_indexes! "tags", [false, false]
|
219
|
-
|
220
|
-
entity["tags"] = "ruby"
|
221
|
-
|
222
|
-
entity.exclude_from_indexes?("tags").must_equal false
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
@@ -1,189 +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 "gcloud/datastore"
|
17
|
-
|
18
|
-
describe Gcloud::Datastore::Key do
|
19
|
-
|
20
|
-
it "behaves correctly when empty" do
|
21
|
-
key = Gcloud::Datastore::Key.new
|
22
|
-
key.kind.must_be :nil?
|
23
|
-
key.id.must_be :nil?
|
24
|
-
key.name.must_be :nil?
|
25
|
-
key.dataset_id.must_be :nil?
|
26
|
-
key.namespace.must_be :nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
it "creates instances with .new" do
|
30
|
-
key = Gcloud::Datastore::Key.new "ThisThing", 1234
|
31
|
-
key.kind.must_equal "ThisThing"
|
32
|
-
key.id.must_equal 1234
|
33
|
-
key.name.must_be :nil?
|
34
|
-
|
35
|
-
key = Gcloud::Datastore::Key.new "ThisThing", "charlie"
|
36
|
-
key.kind.must_equal "ThisThing"
|
37
|
-
key.id.must_be :nil?
|
38
|
-
key.name.must_equal "charlie"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "can set a parent" do
|
42
|
-
key = Gcloud::Datastore::Key.new "ThisThing", 1234
|
43
|
-
key.kind.must_equal "ThisThing"
|
44
|
-
key.id.must_equal 1234
|
45
|
-
key.name.must_be :nil?
|
46
|
-
|
47
|
-
key.parent.must_be :nil?
|
48
|
-
key.parent = Gcloud::Datastore::Key.new "ThatThing", 6789
|
49
|
-
key.parent.wont_be :nil?
|
50
|
-
key.parent.kind.must_equal "ThatThing"
|
51
|
-
key.parent.id.must_equal 6789
|
52
|
-
key.parent.name.must_be :nil?
|
53
|
-
end
|
54
|
-
|
55
|
-
it "can set a dataset_id" do
|
56
|
-
key = Gcloud::Datastore::Key.new "ThisThing", 1234
|
57
|
-
key.kind.must_equal "ThisThing"
|
58
|
-
key.id.must_equal 1234
|
59
|
-
key.name.must_be :nil?
|
60
|
-
|
61
|
-
key.dataset_id.must_be :nil?
|
62
|
-
key.dataset_id = "custom-ds"
|
63
|
-
key.dataset_id.wont_be :nil?
|
64
|
-
key.dataset_id.must_equal "custom-ds"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "can set a namespace" do
|
68
|
-
key = Gcloud::Datastore::Key.new "ThisThing", 1234
|
69
|
-
key.kind.must_equal "ThisThing"
|
70
|
-
key.id.must_equal 1234
|
71
|
-
key.name.must_be :nil?
|
72
|
-
|
73
|
-
key.namespace.must_be :nil?
|
74
|
-
key.namespace = "custom-ns"
|
75
|
-
key.namespace.wont_be :nil?
|
76
|
-
key.namespace.must_equal "custom-ns"
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "path" do
|
80
|
-
it "returns kind and id" do
|
81
|
-
key = Gcloud::Datastore::Key.new "Task", 123456
|
82
|
-
key.path.must_equal [["Task", 123456]]
|
83
|
-
end
|
84
|
-
it "returns kind and name" do
|
85
|
-
key = Gcloud::Datastore::Key.new "Task", "todos"
|
86
|
-
key.path.must_equal [["Task", "todos"]]
|
87
|
-
end
|
88
|
-
it "returns parent when present" do
|
89
|
-
key = Gcloud::Datastore::Key.new "Task", "todos"
|
90
|
-
key.parent = Gcloud::Datastore::Key.new "User", "username"
|
91
|
-
key.path.must_equal [["User", "username"], ["Task", "todos"]]
|
92
|
-
end
|
93
|
-
it "returns all parents when present" do
|
94
|
-
key = Gcloud::Datastore::Key.new "Task", "todos"
|
95
|
-
key.parent = Gcloud::Datastore::Key.new "User", "username"
|
96
|
-
key.parent.parent = Gcloud::Datastore::Key.new "Org", "company"
|
97
|
-
key.path.must_equal [["Org", "company"], ["User", "username"], ["Task", "todos"]]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it "knows if it is complete or not" do
|
102
|
-
key = Gcloud::Datastore::Key.new "Task"
|
103
|
-
key.id.must_be :nil?
|
104
|
-
key.name.must_be :nil?
|
105
|
-
key.wont_be :complete?
|
106
|
-
key.must_be :incomplete?
|
107
|
-
|
108
|
-
key.id = 123455
|
109
|
-
key.id.wont_be :nil?
|
110
|
-
key.name.must_be :nil?
|
111
|
-
key.must_be :complete?
|
112
|
-
key.wont_be :incomplete?
|
113
|
-
|
114
|
-
key.name = "description"
|
115
|
-
key.id.must_be :nil?
|
116
|
-
key.name.wont_be :nil?
|
117
|
-
key.must_be :complete?
|
118
|
-
key.wont_be :incomplete?
|
119
|
-
end
|
120
|
-
|
121
|
-
it "isn't complete is missing kind" do
|
122
|
-
key = Gcloud::Datastore::Key.new "Task"
|
123
|
-
key.kind = nil
|
124
|
-
key.kind.must_be :nil?
|
125
|
-
key.id.must_be :nil?
|
126
|
-
key.name.must_be :nil?
|
127
|
-
key.wont_be :complete?
|
128
|
-
key.must_be :incomplete?
|
129
|
-
|
130
|
-
key.id = 123455
|
131
|
-
key.kind.must_be :nil?
|
132
|
-
key.id.wont_be :nil?
|
133
|
-
key.name.must_be :nil?
|
134
|
-
key.wont_be :complete?
|
135
|
-
key.must_be :incomplete?
|
136
|
-
|
137
|
-
key.name = "description"
|
138
|
-
key.kind.must_be :nil?
|
139
|
-
key.id.must_be :nil?
|
140
|
-
key.name.wont_be :nil?
|
141
|
-
key.wont_be :complete?
|
142
|
-
key.must_be :incomplete?
|
143
|
-
end
|
144
|
-
|
145
|
-
it "returns a correct protocol buffer object" do
|
146
|
-
key = Gcloud::Datastore::Key.new "ThisThing", 1234
|
147
|
-
proto = key.to_proto
|
148
|
-
proto.path_element.count.must_equal 1
|
149
|
-
proto.path_element.last.kind.must_equal "ThisThing"
|
150
|
-
proto.path_element.last.id.must_equal 1234
|
151
|
-
proto.path_element.last.name.must_be :nil?
|
152
|
-
proto.partition_id.dataset_id.must_be :nil?
|
153
|
-
proto.partition_id.namespace.must_be :nil?
|
154
|
-
|
155
|
-
key = Gcloud::Datastore::Key.new "ThisThing", "charlie"
|
156
|
-
key.parent = Gcloud::Datastore::Key.new "ThatThing", "henry"
|
157
|
-
key.dataset_id = "custom-ds"
|
158
|
-
key.namespace = "custom-ns"
|
159
|
-
proto = key.to_proto
|
160
|
-
proto.path_element.count.must_equal 2
|
161
|
-
proto.path_element.first.kind.must_equal "ThatThing"
|
162
|
-
proto.path_element.first.id.must_be :nil?
|
163
|
-
proto.path_element.first.name.must_equal "henry"
|
164
|
-
proto.path_element.last.kind.must_equal "ThisThing"
|
165
|
-
proto.path_element.last.id.must_be :nil?
|
166
|
-
proto.path_element.last.name.must_equal "charlie"
|
167
|
-
proto.partition_id.dataset_id.must_equal "custom-ds"
|
168
|
-
proto.partition_id.namespace.must_equal "custom-ns"
|
169
|
-
end
|
170
|
-
|
171
|
-
it "can be created with a protocol buffer object" do
|
172
|
-
proto = Gcloud::Datastore::Proto::Key.new
|
173
|
-
proto.path_element = [Gcloud::Datastore::Proto::Key::PathElement.new]
|
174
|
-
proto.path_element.first.kind = "AnotherThing"
|
175
|
-
proto.path_element.first.id = 56789
|
176
|
-
proto.partition_id = Gcloud::Datastore::Proto::PartitionId.new
|
177
|
-
proto.partition_id.dataset_id = "custom-ds"
|
178
|
-
proto.partition_id.namespace = "custom-ns"
|
179
|
-
key = Gcloud::Datastore::Key.from_proto proto
|
180
|
-
|
181
|
-
key.wont_be :nil?
|
182
|
-
key.kind.must_equal "AnotherThing"
|
183
|
-
key.id.must_equal 56789
|
184
|
-
key.name.must_be :nil?
|
185
|
-
key.dataset_id.must_equal "custom-ds"
|
186
|
-
key.namespace.must_equal "custom-ns"
|
187
|
-
key.must_be :frozen?
|
188
|
-
end
|
189
|
-
end
|