test: getRequestFromFunction
This commit is contained in:
@@ -151,8 +151,12 @@ class Connection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchFunctions(functionsDirectory: File) {
|
private fun fetchFunctions(functionsDirectory: File) {
|
||||||
functionsDirectory.walk().filter { it.isDirectory }.forEach { directory ->
|
functionsDirectory.walk().filter {
|
||||||
directory.walk().filter { it.isFile }.forEach { file ->
|
it.isDirectory
|
||||||
|
}.forEach { directory ->
|
||||||
|
directory.walk().filter {
|
||||||
|
it.isFile
|
||||||
|
}.forEach { file ->
|
||||||
val fileContent = file.readText()
|
val fileContent = file.readText()
|
||||||
getDefinitions(fileContent).forEach {
|
getDefinitions(fileContent).forEach {
|
||||||
functions[it.name] = it
|
functions[it.name] = it
|
||||||
|
|||||||
@@ -12,7 +12,15 @@ class RequestTest {
|
|||||||
@Test
|
@Test
|
||||||
fun getRequestFromFile() {
|
fun getRequestFromFile() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
val objTest: ObjTest? = Connection(queriesDirectory = resources).getQuery("Test/test").selectOne()
|
val objTest: ObjTest? = Connection(queriesDirectory = resources).getQuery("Test/selectOne").selectOne()
|
||||||
|
assertTrue(objTest!!.id == 2)
|
||||||
|
assertTrue(objTest.name == "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getRequestFromFunction() {
|
||||||
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
|
val objTest: ObjTest? = Connection(functionsDirectory = resources).getFunction("test_function").selectOne()
|
||||||
assertTrue(objTest!!.id == 2)
|
assertTrue(objTest!!.id == 2)
|
||||||
assertTrue(objTest.name == "test")
|
assertTrue(objTest.name == "test")
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/test/resources/sql/function/Test/function_test.sql
Normal file
8
src/test/resources/sql/function/Test/function_test.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION test_function (name text, IN hi text default 'hello', out result json)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
result = json_build_object('id', 2, 'name', 'test');
|
||||||
|
END;
|
||||||
|
$$
|
||||||
Reference in New Issue
Block a user