зеркало из
1
0
Форкнуть 0

integration tests for TableService

This commit is contained in:
Troy Howard 2012-10-17 21:02:55 -07:00
Родитель 7814cf180a
Коммит 9ab388e9b2
13 изменённых файлов: 940 добавлений и 24 удалений

Просмотреть файл

@ -16,18 +16,20 @@ require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe "Create a table" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
after { TableNameHelper.clean }
describe Azure::Storage::Table::TableService do
describe "#create_table" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
after { TableNameHelper.clean }
it "creates a table with a valid name" do
assert subject.create_table(table_name)
end
it "creates a table with a valid name" do
assert subject.create_table(table_name)
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_table "this_table/cannot-exist!"
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_table "this_table.cannot-exist!"
end
end
end
end

Просмотреть файл

@ -0,0 +1,63 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#delete_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:row_key){ "abcd123" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
subject.insert_entity table_name, partition, row_key, entity_properties
}
after { TableNameHelper.clean }
it "deletes an entity" do
assert subject.delete_entity table_name, partition, row_key
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_entity "this_table.cannot-exist!", partition, row_key
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_entity table_name, "this_partition/key#is_invalid", row_key
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_entity table_name, partition, "thisrow/key#is_invalid"
end
end
end
end

Просмотреть файл

@ -0,0 +1,38 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#delete_table" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
before { subject.create_table table_name }
after { TableNameHelper.clean }
it "deletes a table and returns true on success" do
assert subject.delete_table(table_name)
tables = subject.query_tables
tables.wont_include table_name
end
it "errors on an invalid table" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_table "this_table.cannot-exist!"
end
end
end
end

Просмотреть файл

@ -16,20 +16,22 @@ require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe "Get a table" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
before { subject.create_table table_name }
after { TableNameHelper.clean }
describe Azure::Storage::Table::TableService do
describe "#get_table" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
before { subject.create_table table_name }
after { TableNameHelper.clean }
it "gets the last updated time of a valid table" do
result = subject.get_table table_name
result.must_be_kind_of Time
end
it "gets the last updated time of a valid table" do
result = subject.get_table table_name
result.must_be_kind_of Time
end
it "errors on an invalid table" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.get_table "this_table/cannot-exist!"
end
it "errors on an invalid table" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.get_table "this_table.cannot-exist!"
end
end
end
end

Просмотреть файл

@ -0,0 +1,73 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#insert_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:row_key){ "abcd123" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
}
after { TableNameHelper.clean }
it "creates an entity" do
result = subject.insert_entity table_name, partition, row_key, entity_properties
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
entity_properties.each { |k,v|
unless entity_properties[k].class == Time
result.properties[k].must_equal entity_properties[k]
else
result.properties[k].to_i.must_equal entity_properties[k].to_i
end
}
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_entity "this_table.cannot-exist!", partition, row_key, entity_properties
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_entity table_name, "this/partition\\key#is?invalid", row_key, entity_properties
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_entity table_name, partition, "this/partition\\key#is?invalid", entity_properties
end
end
end
end

Просмотреть файл

@ -0,0 +1,131 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#insert_or_merge_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
}
after { TableNameHelper.clean }
it "creates an entity if it does not already exist" do
row_key = "abcd1234"
does_not_exist = true
begin
subject.get_entity table_name, partition, row_key
does_not_exist = false
rescue
end
assert does_not_exist
etag = subject.insert_or_merge_entity table_name, partition, row_key, entity_properties
etag.must_be_kind_of String
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
result.etag.must_equal etag
entity_properties.each { |k,v|
unless entity_properties[k].class == Time
result.properties[k].must_equal entity_properties[k]
else
result.properties[k].to_i.must_equal entity_properties[k].to_i
end
}
end
it "updates an existing entity, merging the properties" do
row_key = "abcd1234_existing"
result = subject.insert_entity table_name, partition, row_key, entity_properties
existing_etag = ""
exists = false
begin
existing = subject.get_entity table_name, partition, row_key
existing_etag = existing.etag
exists = true
rescue
end
assert exists, "cannot verify existing record"
etag = subject.insert_or_merge_entity table_name, partition, row_key, { "NewCustomProperty" => "NewCustomValue" }
etag.must_be_kind_of String
etag.wont_equal existing_etag
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
# retained all existing props
entity_properties.each { |k,v|
unless entity_properties[k].class == Time
result.properties[k].must_equal entity_properties[k]
else
result.properties[k].to_i.must_equal entity_properties[k].to_i
end
}
# and has the new one
result.properties["NewCustomProperty"].must_equal "NewCustomValue"
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_merge_entity "this_table.cannot-exist!", partition, "row_key", entity_properties
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_merge_entity table_name, "this/partition_key#is?invalid", "row_key", entity_properties
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_merge_entity table_name, partition, "this/partition_key#is?invalid", entity_properties
end
end
end
end

Просмотреть файл

@ -0,0 +1,127 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#insert_or_replace_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
}
after { TableNameHelper.clean }
it "creates an entity if it does not already exist" do
row_key = "abcd1234"
does_not_exist = true
begin
subject.get_entity table_name, partition, row_key
does_not_exist = false
rescue
end
assert does_not_exist
etag = subject.insert_or_replace_entity table_name, partition, row_key, entity_properties
etag.must_be_kind_of String
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
result.etag.must_equal etag
entity_properties.each { |k,v|
unless entity_properties[k].class == Time
result.properties[k].must_equal entity_properties[k]
else
result.properties[k].to_i.must_equal entity_properties[k].to_i
end
}
end
it "updates an existing entity, removing any properties not included in the update operation" do
row_key = "abcd1234_existing"
result = subject.insert_entity table_name, partition, row_key, entity_properties
existing_etag = ""
exists = false
begin
existing = subject.get_entity table_name, partition, row_key
existing_etag = existing.etag
exists = true
rescue
end
assert exists, "cannot verify existing record"
etag = subject.insert_or_replace_entity table_name, partition, row_key, { "NewCustomProperty" => "NewCustomValue" }
etag.must_be_kind_of String
etag.wont_equal existing_etag
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
# removed all existing props
entity_properties.each { |k,v|
result.properties.wont_include k
}
# and has the new one
result.properties["NewCustomProperty"].must_equal "NewCustomValue"
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_replace_entity "this_table.cannot-exist!", partition, "row_key", entity_properties
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_replace_entity table_name, "this/partition_key#is?invalid", "row_key", entity_properties
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.insert_or_replace_entity table_name, partition, "this/partition_key#is?invalid", entity_properties
end
end
end
end

Просмотреть файл

@ -0,0 +1,102 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#merge_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:row_key){ "abcd1234_existing" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
subject.insert_entity table_name, partition, row_key, entity_properties
@existing_etag = ""
exists = false
begin
existing = subject.get_entity table_name, partition, row_key
@existing_etag = existing.etag
exists = true
rescue
end
assert exists, "cannot verify existing record"
}
after { TableNameHelper.clean }
it "updates an existing entity, merging the properties" do
etag = subject.merge_entity table_name, partition, row_key, { "NewCustomProperty" => "NewCustomValue" }
etag.must_be_kind_of String
etag.wont_equal @existing_etag
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
# retained all existing props
entity_properties.each { |k,v|
unless entity_properties[k].class == Time
result.properties[k].must_equal entity_properties[k]
else
result.properties[k].to_i.must_equal entity_properties[k].to_i
end
}
# and has the new one
result.properties["NewCustomProperty"].must_equal "NewCustomValue"
end
it "errors on a non-existing row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.merge_entity table_name, partition, "this-row-key-does-not-exist", entity_properties
end
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.merge_entity "this_table.cannot-exist!", partition, row_key, entity_properties
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.merge_entity table_name, "this/partition_key#is?invalid", row_key, entity_properties
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.merge_entity table_name, partition, "this/row_key#is?invalid", entity_properties
end
end
end
end

Просмотреть файл

@ -0,0 +1,182 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#query_entities" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:entities_per_partition){3}
let(:partitions){ ["part1", "part2", "part3"]}
let(:entities){
entities = {}
index = 0
partitions.each { |p|
entities[p] = []
(0..entities_per_partition).each { |i|
entities[p].push "entity-#{index}"
index+=1
}
}
entities
}
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
partitions.each { |p|
entities[p].each { |e|
subject.insert_entity table_name, p, e, entity_properties
}
}
}
after { TableNameHelper.clean }
it "Queries a table for list of entities" do
result, token = subject.query_entities table_name
result.must_be_kind_of Array
result.length.must_equal ((partitions.length + 1) * entities_per_partition)
result.each { |e|
entities[e.partition_key].must_include e.row_key
entity_properties.each { |k,v|
unless v.class == Time
e.properties[k].must_equal v
else
e.properties[k].to_i.must_equal v.to_i
end
}
}
end
it "can constrain by partition and row key, returning zero or one entity" do
partition = partitions[0]
row_key = entities[partition][0]
result, token = subject.query_entities table_name, partition, row_key
result.must_be_kind_of Array
result.length.must_equal 1
result.each { |e|
e.row_key.must_equal row_key
entity_properties.each { |k,v|
unless v.class == Time
e.properties[k].must_equal v
else
e.properties[k].to_i.must_equal v.to_i
end
}
}
end
it "can project a subset of properties, populating sparse properties with nil" do
projection = ["CustomIntegerProperty", "ThisPropertyDoesNotExist"]
result, token = subject.query_entities table_name, nil, nil, projection
result.must_be_kind_of Array
result.length.must_equal ((partitions.length + 1) * entities_per_partition)
result.each { |e|
e.properties.length.must_equal projection.length
e.properties["CustomIntegerProperty"].must_equal entity_properties["CustomIntegerProperty"]
e.properties.must_include "ThisPropertyDoesNotExist"
e.properties["ThisPropertyDoesNotExist"].must_equal nil
}
end
it "can filter by one or more properties, returning a matching set of entities" do
subject.insert_entity table_name, "filter-test-partition", "filter-test-key", entity_properties.merge({ "CustomIntegerProperty" => entity_properties["CustomIntegerProperty"] + 1, "CustomBooleanProperty"=> false})
filter = "CustomIntegerProperty gt #{entity_properties["CustomIntegerProperty"]} and CustomBooleanProperty eq false"
result, token = subject.query_entities table_name, nil, nil, nil, filter
result.must_be_kind_of Array
result.length.must_equal 1
result.first.partition_key.must_equal "filter-test-partition"
filter = "CustomIntegerProperty gt #{entity_properties["CustomIntegerProperty"]} and CustomBooleanProperty eq true"
result, token = subject.query_entities table_name, nil, nil, nil, filter
result.must_be_kind_of Array
result.length.must_equal 0
end
it "can limit the result set using the top parameter" do
result, token = subject.query_entities table_name, nil, nil, nil, nil, 3
result.must_be_kind_of Array
result.length.must_equal 3
token.wont_be_nil
end
it "can page results using the top parameter and continuation_token" do
result, token = subject.query_entities table_name, nil, nil, nil, nil, 3
result.must_be_kind_of Array
result.length.must_equal 3
token.wont_be_nil
result2, token1 = subject.query_entities table_name, nil, nil, nil, nil, 3, token
result2.must_be_kind_of Array
result2.length.must_equal 3
token1.wont_be_nil
result3, token2 = subject.query_entities table_name, nil, nil, nil, nil, 3, token1
result3.must_be_kind_of Array
result3.length.must_equal 3
token2.wont_be_nil
result4, token3 = subject.query_entities table_name, nil, nil, nil, nil, 3, token2
result4.must_be_kind_of Array
result4.length.must_equal 3
token3.must_be_nil
end
it "can combine projection, filtering, and paging in the same query" do
subject.insert_entity table_name, "filter-test-partition", "filter-test-key", entity_properties.merge({ "CustomIntegerProperty" => entity_properties["CustomIntegerProperty"] + 1, "CustomBooleanProperty"=> false})
filter = "CustomIntegerProperty eq #{entity_properties["CustomIntegerProperty"]}"
projection = ["PartitionKey", "CustomIntegerProperty"]
result, token = subject.query_entities table_name, nil, nil, projection, filter, 3
result.must_be_kind_of Array
result.length.must_equal 3
token.wont_be_nil
result.first.properties["CustomIntegerProperty"].must_equal entity_properties["CustomIntegerProperty"]
result.first.properties.length.must_equal 1
result2, token1 = subject.query_entities table_name, nil, nil, projection, filter, 3, token
result2.must_be_kind_of Array
result2.length.must_equal 3
token1.wont_be_nil
result3, token2 = subject.query_entities table_name, nil, nil, projection, filter, 3, token1
result3.must_be_kind_of Array
result3.length.must_equal 3
token2.wont_be_nil
result4, token3 = subject.query_entities table_name, nil, nil, projection, filter, 3, token2
result4.must_be_kind_of Array
result4.length.must_equal 3
token3.must_be_nil
end
end
end

Просмотреть файл

@ -0,0 +1,39 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#query_tables" do
subject { Azure::Storage::Table::TableService.new }
let(:tables){ [TableNameHelper.name, TableNameHelper.name] }
before { tables.each { |t| subject.create_table t } }
after { TableNameHelper.clean }
it "gets a list of tables for the account" do
result, token = subject.query_tables
result.must_be_kind_of Hash
tables.each { |t|
result.must_include t
updated = subject.get_table(t)
# this is a weird, but sometimes it's off by a second
assert (result[t] == updated or result[t] == (updated - 1))
}
end
end
end

Просмотреть файл

@ -0,0 +1,56 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#get/set_acl" do
# TODO: These aren't working...
# subject { Azure::Storage::Table::TableService.new }
# let(:table_name){ TableNameHelper.name }
# let(:signed_identifier) {
# identifier = Azure::Storage::Service::SignedIdentifier.new
# identifier.id = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
# identifier.access_policy = Azure::Storage::Service::AccessPolicy.new
# identifier.access_policy.start = "2009-09-28T08:49:37.0000000Z"
# identifier.access_policy.expiry = "2009-09-29T08:49:37.0000000Z"
# identifier.access_policy.permission = "raud"
# identifier
# }
# before {
# subject.create_table table_name
# }
# after { TableNameHelper.clean }
# it "sets and gets the ACL for a table" do
# require 'azure/core/http/debug_filter'
# subject.with_filter Azure::Core::Http::DebugFilter.new
# subject.filters.rotate!
# assert subject.set_table_acl(table_name, [signed_identifier])
# result = subject.get_table_acl table_name
# result.must_be_kind_of Array
# result.length.wont_be_empty
# result.last.must_be_kind_of Azure::Storage::Service::SignedIdentifier
# result.last.id.must_equal signed_identifier.id
# result.last.access_policy.start.must_equal signed_identifier.access_policy.start
# result.last.access_policy.expiry.must_equal signed_identifier.access_policy.expiry
# result.last.access_policy.permission.must_equal signed_identifier.access_policy.permission
# end
end
end

Просмотреть файл

@ -0,0 +1,98 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/table/table_service"
require "azure/core/http/http_error"
describe Azure::Storage::Table::TableService do
describe "#update_entity" do
subject { Azure::Storage::Table::TableService.new }
let(:table_name){ TableNameHelper.name }
let(:partition){ "testingpartition" }
let(:row_key){ "abcd1234_existing" }
let(:entity_properties){
{
"CustomStringProperty" => "CustomPropertyValue",
"CustomIntegerProperty" => 37,
"CustomBooleanProperty" => true,
"CustomDateProperty" => Time.now
}
}
before {
subject.create_table table_name
subject.insert_entity table_name, partition, row_key, entity_properties
@existing_etag = ""
exists = false
begin
existing = subject.get_entity table_name, partition, row_key
@existing_etag = existing.etag
exists = true
rescue
end
assert exists, "cannot verify existing record"
}
after { TableNameHelper.clean }
it "updates an existing entity, removing any properties not included in the update operation" do
etag = subject.update_entity table_name, partition, row_key, { "NewCustomProperty" => "NewCustomValue" }
etag.must_be_kind_of String
etag.wont_equal @existing_etag
result = subject.get_entity table_name, partition, row_key
result.must_be_kind_of Azure::Storage::Table::Entity
result.table.must_equal table_name
result.partition_key.must_equal partition
result.row_key.must_equal row_key
# removed all existing props
entity_properties.each { |k,v|
result.properties.wont_include k
}
# and has the new one
result.properties["NewCustomProperty"].must_equal "NewCustomValue"
end
it "errors on a non-existing row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_entity table_name, partition, "this-row-key-does-not-exist", entity_properties
end
end
it "errors on an invalid table name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_entity "this_table.cannot-exist!", partition, row_key, entity_properties
end
end
it "errors on an invalid partition key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_entity table_name, "this/partition_key#is?invalid", row_key, entity_properties
end
end
it "errors on an invalid row key" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_entity table_name, partition, "this/row_key#is?invalid", entity_properties
end
end
end
end

Просмотреть файл

@ -34,7 +34,10 @@ end
TableNameHelper = NameGenerator.new do |name|
svc = Azure::Storage::Table::TableService.new
svc.delete_table name
begin
svc.delete_table name
rescue
end
end
# ContainerNameHelper = NameGenerator.new do |name|