Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for column_rename command
- Loading branch information
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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
27
test/command/suite/groonga/column_rename/unknown-column.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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
16
test/command/suite/groonga/column_rename/unknown-column.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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
14
test/command/suite/groonga/column_rename/unknown-table.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "column_rename", | ||
| "dataset": "Droonga", | ||
| "body": { | ||
| "table" : "Unknown" | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |