Navigation Menu

Skip to content

Commit

Permalink
test: Add test for Groonga's delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 24, 2014
1 parent 7482f83 commit 44a570e
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions test/unit/plugins/groonga/test_delete.rb
@@ -0,0 +1,107 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

class DeleteTest < GroongaHandlerTest
def create_handler
Droonga::Plugins::Groonga::Delete::Handler.new("droonga",
@handler.context,
@messages,
@loop)
end

def test_success
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
end
@context["Books"].add("sample")
message = {
"table" => "Books",
"key" => "sample",
}
response = process(:delete, message)
assert_equal(
[NORMALIZED_HEADER_SUCCESS, true],
[normalize_header(response.first), response.last]
)
end

def test_unknown_table
message = {
"table" => "Unknown",
}
response = process(:delete, message)
assert_equal(
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
[normalize_header(response.first), response.last]
)
end

def test_no_identifier
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
end
message = {
"table" => "Books",
}
response = process(:delete, message)
assert_equal(
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
[normalize_header(response.first), response.last]
)
end

data(:key_and_id => { "key" => "key", "id" => 1 },
:id_and_filter => { "id" => 1, "filter" => "filter" },
:key_and_filter => { "key" => "key", "filter" => "filter" })
def test_duplicated_identifier(data)
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
end
message = {
"table" => "Books",
}.merge(data)
response = process(:delete, message)
assert_equal(
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
[normalize_header(response.first), response.last]
)
end

class DeleteTest < self
def test_key
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
end
@context["Books"].add("sample")
process(:delete,
{"table" => "Books", "key" => "sample"})
assert_equal(<<-DUMP, dump)
table_create Books TABLE_HASH_KEY --key_type ShortText
DUMP
end

def test_id
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Ages", :type => :array)
end
@context["Ages"].add(10)
process(:delete,
{"table" => "Ages", "id" => 1})
assert_equal(<<-DUMP, dump)
table_create Books TABLE_HASH_KEY --key_type ShortText
DUMP
end
end
end

0 comments on commit 44a570e

Please sign in to comment.