Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#15: Add tests for all data types #73

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/changes_0.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Code name: Initial Release
* #33: Replaced `cjson.null` in returned row data with `luasql.exasol.NULL`
* #39: Renamed entry module to `luasql.exasol`
* #71: Removed unnecessary exceptions for luacheck
* #15: Added integration tests for all Exasol data types

## Documentation

Expand Down
101 changes: 101 additions & 0 deletions spec/integration/data_types_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
require("busted.runner")()
local driver = require("luasql.exasol")
local config = require("config")

config.configure_logging()

describe("Exasol data types", function()
local env = nil
local connection = nil

before_each(function()
env = driver.exasol()
local connection_params = config.get_connection_params()
connection = assert(env:connect(connection_params.source_name, connection_params.user,
connection_params.password))
end)

after_each(function()
assert.is_true(connection:close())
assert.is_true(env:close())
end)

describe("converted to correct Lua type", function()
local function cast(expression, type)
return string.format("cast(%s as %s)", expression, type)
end
-- See [list of all Exasol data types]
-- (https://docs.exasol.com/db/latest/sql_references/data_types/datatypesoverview.htm)
local test_cases = {
--
-- Boolean
--
{expression = "true", expected_value = true, expected_type = "BOOLEAN"},
{expression = "false", expected_value = false, expected_type = "BOOLEAN"}, --
--
-- Numeric types
--
{expression = "42", expected_value = 42, expected_type = "DECIMAL"},
{expression = "3.141", expected_value = "3.141", expected_type = "DECIMAL"},
{expression = cast("100.123456", "DECIMAL(5,2)"), expected_value = "100.12", expected_type = "DECIMAL"},
{expression = cast("3.141", "DOUBLE PRECISION"), expected_value = 3.141, expected_type = "DOUBLE"}, --
--
-- Sting types
--
{expression = "'abc'", expected_value = "abc", expected_type = "CHAR"},
{expression = cast("'abc'", "CHAR(5)"), expected_value = "abc ", expected_type = "CHAR"},
{expression = cast("'abc'", "VARCHAR(5)"), expected_value = "abc", expected_type = "VARCHAR"}, --
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need a test for UFT-8 vs. ASCII encodings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will add this in another pr.

--
-- Date/time types
--
{expression = cast("'2022-05-31'", "DATE"), expected_value = "2022-05-31", expected_type = "DATE"}, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placement of opening curly bracket looks strange. We might need to check the formatter settings again.

expression = cast("'2021-12-31 23:59:59.999'", "TIMESTAMP"),
expected_value = "2021-12-31 23:59:59.999000",
expected_type = "TIMESTAMP"
}, {
expression = cast("'2021-12-31 23:59:59.999'", "TIMESTAMP WITH LOCAL TIME ZONE"),
expected_value = "2021-12-31 23:59:59.999000",
expected_type = "TIMESTAMP WITH LOCAL TIME ZONE"
}, --
--
-- Interval types
--
{
expression = cast("'5-3'", "INTERVAL YEAR TO MONTH"),
expected_value = "+05-03",
expected_type = "INTERVAL YEAR TO MONTH"
}, {
expression = cast("'2 12:50:10.123'", "INTERVAL DAY TO SECOND"),
expected_value = "+02 12:50:10.123",
expected_type = "INTERVAL DAY TO SECOND"
}, --
--
-- Hashtype type
--
{
expression = cast("'550e8400-e29b-11d4-a716-446655440000'", "HASHTYPE"),
expected_value = "550e8400e29b11d4a716446655440000",
expected_type = "HASHTYPE"
}, --
--
-- Geospatial types
--
{expression = cast("'POINT(1 2)'", "GEOMETRY"), expected_value = "POINT (1 2)", expected_type = "GEOMETRY"},
{
expression = cast("'POINT(1 2)'", "GEOMETRY(1234)"),
expected_value = "POINT (1 2)",
expected_type = "GEOMETRY"
}
}
for _, test in ipairs(test_cases) do
it("Expression " .. test.expression .. " has type " .. test.expected_type, function()
local cur = assert(connection:execute("select " .. test.expression))
finally(function()
assert.is_true(cur:close())
end)
assert.is_same(test.expected_value, cur:fetch()[1])
assert.is_same(test.expected_type, cur:getcoltypes()[1])
end)
end
end)
end)