YUKI Hiroshi
null+****@clear*****
Wed Apr 23 14:17:05 JST 2014
YUKI Hiroshi 2014-04-23 14:17:05 +0900 (Wed, 23 Apr 2014) New Revision: 42dfd41210df0d8672ac22bbca133a54a219ea44 https://github.com/droonga/droonga-engine/commit/42dfd41210df0d8672ac22bbca133a54a219ea44 Message: test: Add tests for column_rename command Added files: test/command/suite/groonga/column_rename/success.expected test/command/suite/groonga/column_rename/success.test test/command/suite/groonga/column_rename/unknown-column.expected test/command/suite/groonga/column_rename/unknown-column.test test/command/suite/groonga/column_rename/unknown-table.expected test/command/suite/groonga/column_rename/unknown-table.test test/unit/plugins/groonga/test_column_rename.rb Added: test/command/suite/groonga/column_rename/success.expected (+39 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/success.expected 2014-04-23 14:17:05 +0900 (81b959b) @@ -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 + ] +} Added: test/command/suite/groonga/column_rename/success.test (+26 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/success.test 2014-04-23 14:17:05 +0900 (694397f) @@ -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" + } +} Added: test/command/suite/groonga/column_rename/unknown-column.expected (+27 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/unknown-column.expected 2014-04-23 14:17:05 +0900 (ee23fa5) @@ -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 + ] +} Added: test/command/suite/groonga/column_rename/unknown-column.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/unknown-column.test 2014-04-23 14:17:05 +0900 (87258da) @@ -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" + } +} Added: test/command/suite/groonga/column_rename/unknown-table.expected (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/unknown-table.expected 2014-04-23 14:17:05 +0900 (21c18d0) @@ -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 + ] +} Added: test/command/suite/groonga/column_rename/unknown-table.test (+7 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/column_rename/unknown-table.test 2014-04-23 14:17:05 +0900 (011253a) @@ -0,0 +1,7 @@ +{ + "type": "column_rename", + "dataset": "Droonga", + "body": { + "table" : "Unknown" + } +} Added: test/unit/plugins/groonga/test_column_rename.rb (+104 -0) 100644 =================================================================== --- /dev/null +++ test/unit/plugins/groonga/test_column_rename.rb 2014-04-23 14:17:05 +0900 (512d97b) @@ -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 -------------- next part -------------- HTML����������������������������...Download