Navigation Menu

Skip to content

Commit

Permalink
test: Add tests for column_rename command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 23, 2014
1 parent 5c96005 commit 42dfd41
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/command/suite/groonga/column_rename/success.expected
@@ -0,0 +1,39 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "table_create.result",
"body": [
[
0,
0.0,
0.0
],
true
]
}
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "column_create.result",
"body": [
[
0,
0.0,
0.0
],
true
]
}
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "column_rename.result",
"body": [
[
0,
0.0,
0.0
],
true
]
}
26 changes: 26 additions & 0 deletions test/command/suite/groonga/column_rename/success.test
@@ -0,0 +1,26 @@
{
"type": "table_create",
"dataset": "Droonga",
"body": {
"name" : "User",
"flags" : "TABLE_PAT_KEY"
}
}
{
"type": "column_create",
"dataset": "Droonga",
"body": {
"table" : "User",
"name" : "age",
"type" : "Int32"
}
}
{
"type": "column_rename",
"dataset": "Droonga",
"body": {
"table" : "User",
"name" : "age",
"new_name" : "level"
}
}
27 changes: 27 additions & 0 deletions test/command/suite/groonga/column_rename/unknown-column.expected
@@ -0,0 +1,27 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "table_create.result",
"body": [
[
0,
0.0,
0.0
],
true
]
}
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "column_rename.result",
"body": [
[
-22,
0.0,
0.0,
"column doesn't exist: <unknown>"
],
false
]
}
16 changes: 16 additions & 0 deletions test/command/suite/groonga/column_rename/unknown-column.test
@@ -0,0 +1,16 @@
{
"type": "table_create",
"dataset": "Droonga",
"body": {
"name" : "User",
"flags" : "TABLE_PAT_KEY"
}
}
{
"type": "column_rename",
"dataset": "Droonga",
"body": {
"table" : "User",
"name" : "unknown"
}
}
14 changes: 14 additions & 0 deletions test/command/suite/groonga/column_rename/unknown-table.expected
@@ -0,0 +1,14 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "column_rename.result",
"body": [
[
-22,
0.0,
0.0,
"table doesn't exist: <Unknown>"
],
false
]
}
7 changes: 7 additions & 0 deletions test/command/suite/groonga/column_rename/unknown-table.test
@@ -0,0 +1,7 @@
{
"type": "column_rename",
"dataset": "Droonga",
"body": {
"table" : "Unknown"
}
}
104 changes: 104 additions & 0 deletions test/unit/plugins/groonga/test_column_rename.rb
@@ -0,0 +1,104 @@
# 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 ColumnRenameTest < GroongaHandlerTest
def create_handler
Droonga::Plugins::Groonga::ColumnRename::Handler.new("droonga",
@handler.context,
@messages,
@loop)
end

def test_success
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
schema.change_table("Books") do |table|
table.column("title", "ShortText", :type => :scalar)
end
end
message = {
"table" => "Books",
"name" => "title",
"new_name" => "label",
}
response = process(:column_rename, message)
assert_equal(
[NORMALIZED_HEADER_SUCCESS, true],
[normalize_header(response.first), response.last]
)
end

def test_unknown_table
message = {
"table" => "Unknown",
"name" => "title",
"new_name" => "label",
"type" => "ShortText",
}
response = process(:column_rename, message)
assert_equal(
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
[normalize_header(response.first), response.last]
)
end

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

def test_rename
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
schema.change_table("Books") do |table|
table.column("title", "ShortText", :type => :scalar)
end
end
process(:column_rename,
{"table" => "Books", "name" => "title", "new_name" => "label"})
assert_equal(<<-SCHEMA, dump)
table_create Books TABLE_HASH_KEY --key_type ShortText
column_create Books label COLUMN_SCALAR ShortText
SCHEMA
end

def test_rename_with_index
Groonga::Schema.define(:context => @context) do |schema|
schema.create_table("Books", :type => :hash)
schema.change_table("Books") do |table|
table.column("title", "ShortText", :type => :scalar)
table.index("Books", "title", :name => "entry_title")
end
end
process(:column_rename,
{"table" => "Books", "name" => "title", "new_name" => "label"})
assert_equal(<<-SCHEMA, dump)
table_create Books TABLE_HASH_KEY --key_type ShortText
column_create Books label COLUMN_SCALAR ShortText
column_create Books entry_title COLUMN_INDEX Books label
SCHEMA
end
end

0 comments on commit 42dfd41

Please sign in to comment.