Skip to content

Instantly share code, notes, and snippets.

@vmesel
Last active November 28, 2022 22:42
Show Gist options
  • Save vmesel/7054f8c3b752ec9a0732bba974acdae4 to your computer and use it in GitHub Desktop.
Save vmesel/7054f8c3b752ec9a0732bba974acdae4 to your computer and use it in GitHub Desktop.
.:: POSTGRES: DROP/CREATE DATABASE
NOTICE: database "prest-test" does not exist, skipping
DROP DATABASE
CREATE DATABASE
.:: POSTGRES: LOAD DATA SCHEMA
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
CREATE TABLE
INSERT 0 1
CREATE VIEW
.:: GOLANG: DOWNLOAD MODULES
.:: PRESTD: PLUGIN BUILD
.:: PRESTD: MIGRATE UP
prest-test
prest-test
exec migrations located in /workspace/testdata/migrations
executed 1 migrations
/workspace/testdata/migrations/001_create_table_test_migrations.up.sql SUCCESS
.:: PRESTD: TESTING STARTING...
prest-test
prest-test
=== RUN Test_basicPasswordCheck
prest-test
prest-test
--- PASS: Test_basicPasswordCheck (0.09s)
=== RUN Test_getSelectQuery
--- PASS: Test_getSelectQuery (0.01s)
=== RUN Test_encrypt
--- PASS: Test_encrypt (0.01s)
=== RUN TestAuthDisable
auth_test.go:72: /auth request POST method, disable auth
test: TestAuthDisable body: 404 page not found
--- PASS: TestAuthDisable (0.01s)
=== RUN TestAuthEnable
prest-test
prest-test
auth_test.go:95: /auth request GET method
test: TestAuthEnable body:
auth_test.go:95: /auth request POST method
test: TestAuthEnable body: user not found
--- PASS: TestAuthEnable (0.06s)
=== RUN TestGetDatabases
prest-test
prest-test
databases_test.go:43: Get databases without custom where clause
test: TestGetDatabases body: [{"datname": "postgres"}, {"datname": "prest-test"}]
databases_test.go:43: Get databases with custom where clause
test: TestGetDatabases body: []
databases_test.go:43: Get databases with custom order clause
test: TestGetDatabases body: [{"datname": "postgres"}, {"datname": "prest-test"}]
databases_test.go:43: Get databases with custom order invalid clause
test: TestGetDatabases body: invalid identifier
databases_test.go:43: Get databases with custom where clause and pagination
test: TestGetDatabases body: []
databases_test.go:43: Get databases with COUNT clause
test: TestGetDatabases body: [{"count": 2}]
databases_test.go:43: Get databases with custom where invalid clause
test: TestGetDatabases body: 0datname: invalid identifier
databases_test.go:43: Get databases with custom where and pagination invalid
test: TestGetDatabases body: strconv.Atoi: parsing "A": invalid syntax
databases_test.go:43: Get databases with noexistent column
test: TestGetDatabases body: pq: column "datatata" does not exist
databases_test.go:43: Get databases with distinct
test: TestGetDatabases body: [{"datname": "postgres"}, {"datname": "prest-test"}]
databases_test.go:43: Get databases with invalid distinct
test: TestGetDatabases body: [{"datname": "postgres"}, {"datname": "prest-test"}]
--- PASS: TestGetDatabases (0.36s)
=== RUN TestGetDatabasesWithDisableAll
test: TestGetDatabasesWithDisableAll body: not authorized to list databases
--- PASS: TestGetDatabasesWithDisableAll (0.03s)
=== RUN TestGetDatabasesWithDisableDatabaseListing
test: TestGetDatabasesWithDisableDatabaseListing body: not authorized to list databases
--- PASS: TestGetDatabasesWithDisableDatabaseListing (0.04s)
=== RUN TestGetSchemas
prest-test
prest-test
schemas_test.go:42: Get schemas without custom where clause
test: TestGetSchemas body: [{"schema_name": "information_schema"}, {"schema_name": "pg_catalog"}, {"schema_name": "pg_toast"}, {"schema_name": "public"}]
schemas_test.go:42: Get schemas with custom where clause
test: TestGetSchemas body: [{"schema_name": "public"}]
schemas_test.go:42: Get schemas with custom order clause
test: TestGetSchemas body: [{"schema_name": "public"}]
schemas_test.go:42: Get schemas with custom order invalid clause
test: TestGetSchemas body: invalid identifier
schemas_test.go:42: Get schemas with custom where clause and pagination
test: TestGetSchemas body: [{"schema_name": "public"}]
schemas_test.go:42: Get schemas with COUNT clause
test: TestGetSchemas body: [{"count": 4}]
schemas_test.go:42: Get schemas with custom where invalid clause
test: TestGetSchemas body: 0schema_name: invalid identifier
schemas_test.go:42: Get schemas with noexistent column
test: TestGetSchemas body: pq: column "schematame" does not exist
schemas_test.go:42: Get schemas with distinct clause
test: TestGetSchemas body: [{"schema_name": "public"}]
--- PASS: TestGetSchemas (0.41s)
=== RUN TestVersionDependentGetSchemas
schemas_test.go:70: Get schemas with custom where and pagination invalid
test: TestVersionDependentGetSchemas body: strconv.Atoi: parsing "A": invalid syntax
--- PASS: TestVersionDependentGetSchemas (0.00s)
=== RUN TestGetSchemasWithDisableAll
test: TestGetSchemasWithDisableAll body: not authorized to list schemas
--- PASS: TestGetSchemasWithDisableAll (0.02s)
=== RUN TestExecuteScriptQuery
sql_test.go:55: Execute script GET method
Aqui 1
prest-test
GET
fulltable
get_all
<nil>
{false false false false}
Aqui 1 22
2022/11/28 20:02:56 http: panic serving 127.0.0.1:40060: runtime error: invalid memory address or nil pointer dereference
goroutine 256 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteScriptQuery(0xc0000a3c00, {0xd6de46, 0x9}, {0xd6cce4, 0x7})
/workspace/controllers/sql.go:25 +0x4db
github.com/prest/prest/controllers.TestExecuteScriptQuery.func1({0xe939c0, 0xc00018a7e0}, 0xc0000a3be8?)
/workspace/controllers/sql_test.go:22 +0x5c
net/http.HandlerFunc.ServeHTTP(0xdb3368, {0xe939c0, 0xc00018a7e0}, 0xc0000836c0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc00049c0c0, {0xe939c0, 0xc00018a7e0}, 0xc0000a3a00)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc00025a840?}, {0xe939c0, 0xc00018a7e0}, 0xc0000a3a00)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000232fa0, {0xe94060, 0xc0002f12f0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:56
Error: Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:38767/testing/script-get/?field1=gopher", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteScriptQuery
Messages: error on Do Request
error Get "http://127.0.0.1:38767/testing/script-get/?field1=gopher": EOF sql_test.go:55: Execute script POST method
Aqui 1
prest-test
POST
fulltable
write_all
<nil>
{false false false false}
Aqui 1 22
2022/11/28 20:02:56 http: panic serving 127.0.0.1:40062: runtime error: invalid memory address or nil pointer dereference
goroutine 229 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteScriptQuery(0xc00007d600, {0xd6de46, 0x9}, {0xd6e1b8, 0x9})
/workspace/controllers/sql.go:25 +0x4db
github.com/prest/prest/controllers.TestExecuteScriptQuery.func2({0xe939c0, 0xc00048e380}, 0xc00007d5e8?)
/workspace/controllers/sql_test.go:32 +0x5a
net/http.HandlerFunc.ServeHTTP(0xdb3370, {0xe939c0, 0xc00048e380}, 0xc000225d40?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc00049c0c0, {0xe939c0, 0xc00048e380}, 0xc000461100)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0002f13b0?}, {0xe939c0, 0xc00048e380}, 0xc000461100)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000282b40, {0xe94060, 0xc0002f12f0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:56
Error: Expected nil, but got: &url.Error{Op:"Post", URL:"http://127.0.0.1:38767/testing/script-post/?field1=gopherzin&field2=pereira", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteScriptQuery
Messages: error on Do Request
error Post "http://127.0.0.1:38767/testing/script-post/?field1=gopherzin&field2=pereira": EOF--- FAIL: TestExecuteScriptQuery (0.02s)
=== RUN TestExecuteFromScripts
sql_test.go:86: Get results using scripts and funcs by GET method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43976: runtime error: invalid memory address or nil pointer dereference
goroutine 230 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc0005120e0}, 0xc000461500)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc0005120e0}, 0xc000461400)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc0005120e0}, 0xc000083ba0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc0005120e0}, 0xc000461200)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0002f15f0?}, {0xe939c0, 0xc0005120e0}, 0xc000461200)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000282be0, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/funcs", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Get "http://127.0.0.1:33197/_QUERIES/fulltable/funcs": EOF sql_test.go:86: Get results using scripts by GET method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43978: runtime error: invalid memory address or nil pointer dereference
goroutine 269 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc00048e460}, 0xc00007da00)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc00048e460}, 0xc00007d900)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc00048e460}, 0xc000082ea0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc00048e460}, 0xc00007d700)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0003ab200?}, {0xe939c0, 0xc00048e460}, 0xc00007d700)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc0001c4b40, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/get_all?field1=gopher", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Get "http://127.0.0.1:33197/_QUERIES/fulltable/get_all?field1=gopher": EOF sql_test.go:86: Get results using scripts by GET method (2)
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43980: runtime error: invalid memory address or nil pointer dereference
goroutine 273 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc00048e540}, 0xc00007df00)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc00048e540}, 0xc00007de00)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc00048e540}, 0xc000082ea0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc00048e540}, 0xc00007dc00)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0003ab740?}, {0xe939c0, 0xc00048e540}, 0xc00007dc00)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc0001c4be0, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/get_header", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Get "http://127.0.0.1:33197/_QUERIES/fulltable/get_header": EOF sql_test.go:86: Get results using scripts by POST method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43982: runtime error: invalid memory address or nil pointer dereference
goroutine 291 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc00018a9a0}, 0xc000430200)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc00018a9a0}, 0xc000430100)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc00018a9a0}, 0xc000082ea0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc00018a9a0}, 0xc000188100)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0003ab980?}, {0xe939c0, 0xc00018a9a0}, 0xc000188100)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc0001c4c80, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Post", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/write_all?field1=gopherzin&field2=pereira", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Post "http://127.0.0.1:33197/_QUERIES/fulltable/write_all?field1=gopherzin&field2=pereira": EOF sql_test.go:86: Get results using scripts by PUT method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43984: runtime error: invalid memory address or nil pointer dereference
goroutine 292 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc0005121c0}, 0xc000461900)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc0005121c0}, 0xc000461800)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc0005121c0}, 0xc000225d40?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc0005121c0}, 0xc000461600)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0002f1800?}, {0xe939c0, 0xc0005121c0}, 0xc000461600)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc0001c4d20, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Put", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/put_all?field1=trump&field2=pereira", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Put "http://127.0.0.1:33197/_QUERIES/fulltable/put_all?field1=trump&field2=pereira": EOF sql_test.go:86: Get results using scripts by PATCH method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43986: runtime error: invalid memory address or nil pointer dereference
goroutine 311 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc00018aa80}, 0xc000430700)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc00018aa80}, 0xc000430600)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc00018aa80}, 0xc0003f1040?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc00018aa80}, 0xc000430400)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc00025bf20?}, {0xe939c0, 0xc00018aa80}, 0xc000430400)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000233b80, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Patch", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/patch_all?field1=temer&field2=trump", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Patch "http://127.0.0.1:33197/_QUERIES/fulltable/patch_all?field1=temer&field2=trump": EOF sql_test.go:86: Get results using scripts by DELETE method
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43988: runtime error: invalid memory address or nil pointer dereference
goroutine 313 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc0005122a0}, 0xc000461e00)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc0005122a0}, 0xc000461d00)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc0005122a0}, 0xc0003f1040?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc0005122a0}, 0xc000430800)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0003e21b0?}, {0xe939c0, 0xc0005122a0}, 0xc000430800)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000233cc0, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Delete", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/delete_all?field1=trump", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Delete "http://127.0.0.1:33197/_QUERIES/fulltable/delete_all?field1=trump": EOF sql_test.go:86: Get errors using nonexistent folder
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43990: runtime error: invalid memory address or nil pointer dereference
goroutine 314 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc000512380}, 0xc00057a100)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc000512380}, 0xc00057a000)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc000512380}, 0xc0000836c0?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc000512380}, 0xc000430900)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0003e2270?}, {0xe939c0, 0xc000512380}, 0xc000430900)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000233ea0, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Delete", URL:"http://127.0.0.1:33197/_QUERIES/fullnon/delete_all?field1=trump", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Delete "http://127.0.0.1:33197/_QUERIES/fullnon/delete_all?field1=trump": EOF sql_test.go:86: Get errors using nonexistent script
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43992: runtime error: invalid memory address or nil pointer dereference
goroutine 323 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc000512460}, 0xc00057a500)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc000512460}, 0xc00057a400)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc000512460}, 0xc000224d00?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc000512460}, 0xc00057a200)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0000dc660?}, {0xe939c0, 0xc000512460}, 0xc00057a200)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc000282c80, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Delete", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/some_com_all?field1=trump", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Delete "http://127.0.0.1:33197/_QUERIES/fulltable/some_com_all?field1=trump": EOF sql_test.go:86: Get errors with invalid execution of sql
2022/11/28 20:02:56 http: panic serving 127.0.0.1:43994: runtime error: invalid memory address or nil pointer dereference
goroutine 301 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0x106
panic({0xcdb080, 0x1212fb0})
/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/prest/prest/controllers.ExecuteFromScripts({0xe939c0, 0xc00018ab60}, 0xc000430c00)
/workspace/controllers/sql.go:59 +0x19b
net/http.HandlerFunc.ServeHTTP(...)
/usr/local/go/src/net/http/server.go:2084
github.com/prest/prest/controllers.setHTTPTimeoutMiddleware.func1({0xe939c0, 0xc00018ab60}, 0xc000430b00)
/workspace/controllers/tables_test.go:366 +0x3ed
net/http.HandlerFunc.ServeHTTP(0xc000097710, {0xe939c0, 0xc00018ab60}, 0xc0001ca000?)
/usr/local/go/src/net/http/server.go:2084 +0x4e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000306240, {0xe939c0, 0xc00018ab60}, 0xc000188400)
/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x362
net/http.serverHandler.ServeHTTP({0xc0004101b0?}, {0xe939c0, 0xc00018ab60}, 0xc000188400)
/usr/local/go/src/net/http/server.go:2916 +0x897
net/http.(*conn).serve(0xc0001c5180, {0xe94060, 0xc0002f14d0})
/usr/local/go/src/net/http/server.go:1966 +0xbab
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x80d
testutils.go:35:
Error Trace: /workspace/controllers/testutils.go:35
/workspace/controllers/sql_test.go:87
Error: Expected nil, but got: &url.Error{Op:"Post", URL:"http://127.0.0.1:33197/_QUERIES/fulltable/create_table?field1=test7", Err:(*errors.errorString)(0xc00011a0f0)}
Test: TestExecuteFromScripts
Messages: error on Do Request
error Post "http://127.0.0.1:33197/_QUERIES/fulltable/create_table?field1=test7": EOF--- FAIL: TestExecuteFromScripts (0.07s)
=== RUN TestRenderWithXML
prest-test
prest-test
sql_test.go:112: Get schemas with COUNT clause with XML Render
[negroni] 2022-11-28T20:02:56Z | 200 | 28.8277ms | 127.0.0.1:35719 | GET /schemas
test: TestRenderWithXML body: <objects><object><count>4</count></object></objects>
--- PASS: TestRenderWithXML (0.06s)
=== RUN TestGetTables
tables_test.go:56: Get tables without custom where clause
test: TestGetTables body: [{"name": "Reply", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "Reply_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "prest_users", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "prest_users_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "schema_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test2", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test4", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test4_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test5", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test5_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test6", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test6_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test7", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test7_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test8", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testarray", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "testarray_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testjson", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "view_test", "type": "view", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with custom where clause
test: TestGetTables body: [{"name": "test", "type": "table", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with custom order clause
test: TestGetTables body: [{"name": "Reply", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "Reply_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "prest_users", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "prest_users_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "schema_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test2", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test4", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test4_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test5", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test5_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test6", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test6_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test7", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test7_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test8", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testarray", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "testarray_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testjson", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "view_test", "type": "view", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with custom where clause and pagination
test: TestGetTables body: [{"name": "test", "type": "table", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with COUNT clause
test: TestGetTables body: [{"name": "Reply", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "Reply_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "prest_users", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "prest_users_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "schema_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test2", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test4", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test4_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test5", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test5_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test6", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test6_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test7", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test7_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test8", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testarray", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "testarray_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testjson", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "view_test", "type": "view", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with distinct clause
test: TestGetTables body: [{"name": "Reply", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "Reply_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "prest_users", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "prest_users_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "schema_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "table_to_view_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test2", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test3_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test4", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test4_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test5", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test5_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test6", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test6_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test7", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test7_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test8", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_deleteonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_empty_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_group_by_table_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_jsonb_bug_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_list_only_id_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_migrations", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_readonly_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "test_write_and_delete_access_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testarray", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "testarray_id_seq", "type": "sequence", "owner": "postgres", "schema": "public"}, {"name": "testjson", "type": "table", "owner": "postgres", "schema": "public"}, {"name": "view_test", "type": "view", "owner": "postgres", "schema": "public"}]
tables_test.go:56: Get tables with custom where invalid clause
test: TestGetTables body: could not perform WhereByRequest: 0c.relname: invalid identifier
tables_test.go:56: Get tables with ORDER BY and invalid column
test: TestGetTables body: could not perform OrderByRequest: invalid identifier
tables_test.go:56: Get tables with noexistent column
test: TestGetTables body: pq: column c.rolooo does not exist
--- PASS: TestGetTables (0.32s)
=== RUN TestGetTablesByDatabaseAndSchema
tables_test.go:87: Get tables by database and schema without custom where clause
test: TestGetTablesByDatabaseAndSchema body: [{"name": "Reply", "schema": "public", "database": "prest-test"}, {"name": "prest_users", "schema": "public", "database": "prest-test"}, {"name": "schema_migrations", "schema": "public", "database": "prest-test"}, {"name": "table_to_view", "schema": "public", "database": "prest-test"}, {"name": "test", "schema": "public", "database": "prest-test"}, {"name": "test2", "schema": "public", "database": "prest-test"}, {"name": "test3", "schema": "public", "database": "prest-test"}, {"name": "test4", "schema": "public", "database": "prest-test"}, {"name": "test5", "schema": "public", "database": "prest-test"}, {"name": "test6", "schema": "public", "database": "prest-test"}, {"name": "test7", "schema": "public", "database": "prest-test"}, {"name": "test8", "schema": "public", "database": "prest-test"}, {"name": "test_deleteonly_access", "schema": "public", "database": "prest-test"}, {"name": "test_empty_table", "schema": "public", "database": "prest-test"}, {"name": "test_group_by_table", "schema": "public", "database": "prest-test"}, {"name": "test_jsonb_bug", "schema": "public", "database": "prest-test"}, {"name": "test_list_only_id", "schema": "public", "database": "prest-test"}, {"name": "test_migrations", "schema": "public", "database": "prest-test"}, {"name": "test_readonly_access", "schema": "public", "database": "prest-test"}, {"name": "test_write_and_delete_access", "schema": "public", "database": "prest-test"}, {"name": "testarray", "schema": "public", "database": "prest-test"}, {"name": "testjson", "schema": "public", "database": "prest-test"}]
tables_test.go:87: Get tables by database and schema with custom where clause
test: TestGetTablesByDatabaseAndSchema body: [{"name": "test", "schema": "public", "database": "prest-test"}]
tables_test.go:87: Get tables by database and schema with order clause
test: TestGetTablesByDatabaseAndSchema body: [{"name": "test", "schema": "public", "database": "prest-test"}]
tables_test.go:87: Get tables by database and schema with custom where clause and pagination
test: TestGetTablesByDatabaseAndSchema body: [{"name": "test", "schema": "public", "database": "prest-test"}]
tables_test.go:87: Get tables by database and schema with distinct clause
test: TestGetTablesByDatabaseAndSchema body: [{"name": "Reply", "schema": "public", "database": "prest-test"}, {"name": "prest_users", "schema": "public", "database": "prest-test"}, {"name": "schema_migrations", "schema": "public", "database": "prest-test"}, {"name": "table_to_view", "schema": "public", "database": "prest-test"}, {"name": "test", "schema": "public", "database": "prest-test"}, {"name": "test2", "schema": "public", "database": "prest-test"}, {"name": "test3", "schema": "public", "database": "prest-test"}, {"name": "test4", "schema": "public", "database": "prest-test"}, {"name": "test5", "schema": "public", "database": "prest-test"}, {"name": "test6", "schema": "public", "database": "prest-test"}, {"name": "test7", "schema": "public", "database": "prest-test"}, {"name": "test8", "schema": "public", "database": "prest-test"}, {"name": "test_deleteonly_access", "schema": "public", "database": "prest-test"}, {"name": "test_empty_table", "schema": "public", "database": "prest-test"}, {"name": "test_group_by_table", "schema": "public", "database": "prest-test"}, {"name": "test_jsonb_bug", "schema": "public", "database": "prest-test"}, {"name": "test_list_only_id", "schema": "public", "database": "prest-test"}, {"name": "test_migrations", "schema": "public", "database": "prest-test"}, {"name": "test_readonly_access", "schema": "public", "database": "prest-test"}, {"name": "test_write_and_delete_access", "schema": "public", "database": "prest-test"}, {"name": "testarray", "schema": "public", "database": "prest-test"}, {"name": "testjson", "schema": "public", "database": "prest-test"}]
tables_test.go:87: Get tables by database and schema with custom where invalid clause
test: TestGetTablesByDatabaseAndSchema body: could not perform WhereByRequest: 0t.tablename: invalid identifier
tables_test.go:87: Get tables by databases and schema with custom where and pagination invalid
test: TestGetTablesByDatabaseAndSchema body: could not perform PaginateIfPossible: strconv.Atoi: parsing "A": invalid syntax
tables_test.go:87: Get tables by databases and schema with ORDER BY and column invalid
test: TestGetTablesByDatabaseAndSchema body: could not perform OrderByRequest: invalid identifier
tables_test.go:87: Get tables by databases with noexistent column
2022/11/28 20:02:57 [error] pq: column t.taababa does not exist
test: TestGetTablesByDatabaseAndSchema body: pq: column t.taababa does not exist
tables_test.go:87: Get tables by databases with not configured database
test: TestGetTablesByDatabaseAndSchema body: database not registered: random
--- PASS: TestGetTablesByDatabaseAndSchema (0.30s)
=== RUN TestSelectFromTables
tables_test.go:154: execute select in a table with array
test: TestSelectFromTables body: [{"id": 100, "data": ["Gohan", "Goten"]}]
tables_test.go:154: execute select in a table without custom where clause
test: TestSelectFromTables body: [{"id": 1, "name": "prest tester"}, {"id": 2, "name": "tester02"}]
tables_test.go:154: execute select in a table case sentive
test: TestSelectFromTables body: [{"id": 1, "name": "prest tester"}]
testutils.go:52:
Error Trace: /workspace/controllers/testutils.go:52
/workspace/controllers/tables_test.go:159
Error: Should be true
Test: TestSelectFromTables
Messages: expected "[{\"id\": 1, \"name\": \"prest tester\"}, {\"id\": 2, \"name\": \"prest-test-insert\"}, {\"id\": 3, \"name\": \"prest-test-insert-ctx\"}, {\"id\": 4, \"name\": \"3prest-test-batch-insert\"}, {\"id\": 5, \"name\": \"3batch-prest-test-insert\"}, {\"id\": 6, \"name\": \"3prest-test-batch-insert-ctx\"}, {\"id\": 7, \"name\": \"3batch-prest-test-insert-ctx\"}, {\"id\": 8, \"name\": \"copy-ctx\"}, {\"id\": 9, \"name\": \"copy-ctx\"}, {\"id\": 10, \"name\": \"copy\"}, {\"id\": 11, \"name\": \"copy\"}]", got: "[{\"id\": 1, \"name\": \"prest tester\"}]"
tables_test.go:154: execute select in a table with count all fields *
test: TestSelectFromTables body: [{"count": 2}]
tables_test.go:154: execute select in a table with count function
test: TestSelectFromTables body: [{"count": 2}]
tables_test.go:154: execute select in a table with custom where clause
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with custom join clause
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with order clause empty
test: TestSelectFromTables body: [{"id": 1, "name": "prest tester"}, {"id": 2, "name": "tester02"}]
tables_test.go:154: execute select in a table with custom where clause and pagination
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with select fields
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with select *
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with select * and distinct
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a table with group by clause
test: TestSelectFromTables body: [{"age": 19, "sum": 7997}, {"age": 20, "sum": 1350}]
tables_test.go:154: execute select in a table with group by and having clause
test: TestSelectFromTables body: [{"age": 19, "sum": 7997}]
tables_test.go:154: execute select in a view without custom where clause
test: TestSelectFromTables body: [{"player": "gopher"}]
tables_test.go:154: execute select in a view with count all fields *
test: TestSelectFromTables body: [{"count": 1}]
tables_test.go:154: execute select in a view with count function
test: TestSelectFromTables body: [{"count": 1}]
tables_test.go:154: execute select in a view with count function check return list
test: TestSelectFromTables body: [{"count": 1}]
tables_test.go:154: execute select in a view with count function check return object (_count_first)
test: TestSelectFromTables body: {"count":1}
tables_test.go:154: execute select in a view with order function
test: TestSelectFromTables body: [{"player": "gopher"}]
tables_test.go:154: execute select in a view with custom where clause
test: TestSelectFromTables body: [{"player": "gopher"}]
tables_test.go:154: execute select in a view with custom join clause
test: TestSelectFromTables body: []
tables_test.go:154: execute select in a view with custom where clause and pagination
test: TestSelectFromTables body: [{"player": "gopher"}]
tables_test.go:154: execute select in a view with select fields
test: TestSelectFromTables body: [{"player": "gopher"}]
tables_test.go:154: execute select in a table with invalid join clause
test: TestSelectFromTables body: could not perform JoinByRequest: invalid number of arguments in join statement
tables_test.go:154: execute select in a table with invalid where clause
test: TestSelectFromTables body: could not perform WhereByRequest: 0name: invalid identifier
tables_test.go:154: execute select in a table with order clause and column invalid
test: TestSelectFromTables body: could not perform OrderByRequest: invalid identifier
tables_test.go:154: execute select in a table with invalid pagination clause
test: TestSelectFromTables body: could not perform PaginateIfPossible: strconv.Atoi: parsing "A": invalid syntax
tables_test.go:154: execute select in a table with invalid where clause
test: TestSelectFromTables body: could not perform WhereByRequest: 0name: invalid identifier
tables_test.go:154: execute select in a table with invalid count clause
test: TestSelectFromTables body: could not perform CountByRequest: invalid identifier
tables_test.go:154: execute select in a table with invalid order clause
test: TestSelectFromTables body: could not perform OrderByRequest: invalid identifier
tables_test.go:154: execute select in a table with invalid fields using group by clause
test: TestSelectFromTables body: you don't have permission for this action, please check the permitted fields for this table
tables_test.go:154: execute select in a table with invalid fields using group by and having clause
test: TestSelectFromTables body: you don't have permission for this action, please check the permitted fields for this table
tables_test.go:154: execute select in a view with an other column
test: TestSelectFromTables body: you don't have permission for this action, please check the permitted fields for this table
tables_test.go:154: execute select in a view with where and column invalid
test: TestSelectFromTables body: could not perform WhereByRequest: 0celphone: invalid identifier
tables_test.go:154: execute select in a view with custom join clause invalid
test: TestSelectFromTables body: could not perform JoinByRequest: invalid number of arguments in join statement
tables_test.go:154: execute select in a view with custom where clause and pagination invalid
test: TestSelectFromTables body: could not perform PaginateIfPossible: strconv.Atoi: parsing "A": invalid syntax
tables_test.go:154: execute select in a view with order by and column invalid
test: TestSelectFromTables body: could not perform OrderByRequest: invalid identifier
tables_test.go:154: execute select in a view with count column invalid
test: TestSelectFromTables body: could not perform CountByRequest: invalid identifier
tables_test.go:154: execute select in a db that does not exist
test: TestSelectFromTables body: database not registered: invalid
--- FAIL: TestSelectFromTables (0.92s)
=== RUN TestInsertInTables
tables_test.go:201: execute insert in a table with array field
test: TestInsertInTables body: {"id":1,"data":["value 1","value 2","value 3"]}
tables_test.go:201: execute insert in a table with jsonb field
test: TestInsertInTables body: {"name":"prest-test","data":{"obj": {"emp": "prestd"}, "term": "name", "subterm": ["names", "of", "subterms"]}}
tables_test.go:201: execute insert in a table without custom where clause
test: TestInsertInTables body: {"id":3,"name":"prest-test"}
tables_test.go:201: execute insert in a table with invalid database
test: TestInsertInTables body: database not registered: 0prest-test
tables_test.go:201: execute insert in a table with invalid schema
2022/11/28 20:02:58 [error] pq: relation "0public.test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "0public.test" does not exist
test: TestInsertInTables body: pq: relation "0public.test" does not exist
tables_test.go:201: execute insert in a table with invalid table
2022/11/28 20:02:58 [error] pq: relation "public.0test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "public.0test" does not exist
test: TestInsertInTables body: pq: relation "public.0test" does not exist
tables_test.go:201: execute insert in a table with invalid body
test: TestInsertInTables body: could not perform InsertInTables: body is empty
tables_test.go:201: execute insert in a database that does not exist
test: TestInsertInTables body: database not registered: invalid
--- PASS: TestInsertInTables (0.17s)
=== RUN TestBatchInsertInTables
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_array_field
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_jsonb_field
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_without_custom_where_clause
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_database
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_schema
2022/11/28 20:02:58 [error] pq: relation "0public.test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "0public.test" does not exist
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_table
2022/11/28 20:02:58 [error] pq: relation "public.0test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "public.0test" does not exist
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_body
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_array_field_with_copy
=== RUN TestBatchInsertInTables/execute_insert_in_a_table_with_jsonb_field_with_copy
=== RUN TestBatchInsertInTables/execute_insert_in_a_db_that_does_not_exist
--- PASS: TestBatchInsertInTables (0.24s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_array_field (0.05s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_jsonb_field (0.04s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_without_custom_where_clause (0.04s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_database (0.00s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_schema (0.02s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_table (0.02s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_invalid_body (0.01s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_array_field_with_copy (0.03s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_table_with_jsonb_field_with_copy (0.03s)
--- PASS: TestBatchInsertInTables/execute_insert_in_a_db_that_does_not_exist (0.00s)
=== RUN TestDeleteFromTable
tables_test.go:298: execute delete in a table without custom where clause
test: TestDeleteFromTable body: {"rows_affected":5}
tables_test.go:298: excute delete in a table with where clause
test: TestDeleteFromTable body: {"rows_affected":0}
tables_test.go:298: execute delete in a table with invalid database
test: TestDeleteFromTable body: database not registered: 0prest-test
tables_test.go:298: execute delete in a table with invalid schema
2022/11/28 20:02:58 [msg] could not prepare sql: DELETE FROM "prest-test"."0public"."test"
Error: pq: relation "0public.test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "0public.test" does not exist
test: TestDeleteFromTable body: pq: relation "0public.test" does not exist
tables_test.go:298: execute delete in a table with invalid table
2022/11/28 20:02:58 [msg] could not prepare sql: DELETE FROM "prest-test"."public"."0test"
Error: pq: relation "public.0test" does not exist
2022/11/28 20:02:58 [msg] pq: relation "public.0test" does not exist
test: TestDeleteFromTable body: pq: relation "public.0test" does not exist
tables_test.go:298: execute delete in a table with invalid where clause
test: TestDeleteFromTable body: could not perform WhereByRequest: 0name: invalid identifier
tables_test.go:298: execute delete in a invalid db
test: TestDeleteFromTable body: database not registered: invalid
--- PASS: TestDeleteFromTable (0.13s)
=== RUN TestUpdateFromTable
tables_test.go:333: execute update in a table without custom where clause
test: TestUpdateFromTable body: {"rows_affected":0}
test: TestUpdateFromTable body: {"rows_affected":0}
tables_test.go:333: execute update in a table with where clause
test: TestUpdateFromTable body: {"rows_affected":0}
test: TestUpdateFromTable body: {"rows_affected":0}
tables_test.go:333: execute update in a table with where clause and returning all fields
test: TestUpdateFromTable body: null
test: TestUpdateFromTable body: null
tables_test.go:333: execute update in a table with where clause and returning name field
test: TestUpdateFromTable body: null
test: TestUpdateFromTable body: null
tables_test.go:333: execute update in a table with invalid database
test: TestUpdateFromTable body: database not registered: 0prest-test
test: TestUpdateFromTable body: database not registered: 0prest-test
tables_test.go:333: execute update in a table with invalid schema
2022/11/28 20:02:59 [error] could not prepare sql: UPDATE "prest-test"."0public"."test" SET "name"=$1
Error: pq: relation "0public.test" does not exist
test: TestUpdateFromTable body: pq: relation "0public.test" does not exist
2022/11/28 20:02:59 [error] could not prepare sql: UPDATE "prest-test"."0public"."test" SET "name"=$1
Error: pq: relation "0public.test" does not exist
test: TestUpdateFromTable body: pq: relation "0public.test" does not exist
tables_test.go:333: execute update in a table with invalid table
2022/11/28 20:02:59 [error] could not prepare sql: UPDATE "prest-test"."public"."0test" SET "name"=$1
Error: pq: relation "public.0test" does not exist
test: TestUpdateFromTable body: pq: relation "public.0test" does not exist
2022/11/28 20:02:59 [error] could not prepare sql: UPDATE "prest-test"."public"."0test" SET "name"=$1
Error: pq: relation "public.0test" does not exist
test: TestUpdateFromTable body: pq: relation "public.0test" does not exist
tables_test.go:333: execute update in a table with invalid where clause
test: TestUpdateFromTable body: could not perform WhereByRequest: 0name: invalid identifier
test: TestUpdateFromTable body: could not perform WhereByRequest: 0name: invalid identifier
tables_test.go:333: execute update in a table with invalid body
test: TestUpdateFromTable body: could not perform UPDATE: body is empty
test: TestUpdateFromTable body: could not perform UPDATE: body is empty
tables_test.go:333: execute update in a invalid db
test: TestUpdateFromTable body: database not registered: invalid
test: TestUpdateFromTable body: database not registered: invalid
--- PASS: TestUpdateFromTable (0.31s)
=== RUN TestShowTable
tables_test.go:359: execute select in a table test custom information table
test: TestShowTable body: [{"position": 1, "data_type": "integer", "max_length": 32, "table_name": "test", "column_name": "id", "is_nullable": "NO", "is_generated": "NEVER", "is_updatable": "YES", "table_schema": "public", "default_value": "nextval('test_id_seq'::regclass)"}, {"position": 2, "data_type": "text", "max_length": null, "table_name": "test", "column_name": "name", "is_nullable": "YES", "is_generated": "NEVER", "is_updatable": "YES", "table_schema": "public", "default_value": null}]
tables_test.go:359: execute select in a table test2 custom information table
test: TestShowTable body: [{"position": 1, "data_type": "text", "max_length": null, "table_name": "test2", "column_name": "name", "is_nullable": "YES", "is_generated": "NEVER", "is_updatable": "YES", "table_schema": "public", "default_value": null}, {"position": 2, "data_type": "integer", "max_length": 32, "table_name": "test2", "column_name": "number", "is_nullable": "YES", "is_generated": "NEVER", "is_updatable": "YES", "table_schema": "public", "default_value": null}]
tables_test.go:359: execute select in a invalid db
test: TestShowTable body: database not registered: invalid
--- PASS: TestShowTable (0.14s)
FAIL
coverage: 78.2% of statements
FAIL github.com/prest/prest/controllers 3.906s
FAIL
.:: POSTGRES: DROP DATABASES
DROP DATABASE
@vmesel
Copy link
Author

vmesel commented Nov 28, 2022

diff --git a/adapters/postgres/errors.go b/adapters/postgres/errors.go
index eacc619..c5793ad 100644
--- a/adapters/postgres/errors.go
+++ b/adapters/postgres/errors.go
@@ -11,5 +11,6 @@ var (
 	ErrInvalidOperator         = errors.New("invalid operator")
 	ErrInvalidGroupFn          = errors.New("invalid group function")
 	// ErrBodyEmpty err throw when body is empty
-	ErrBodyEmpty = errors.New("body is empty")
+	ErrBodyEmpty               = errors.New("body is empty")
+	ErrEmptyOrInvalidSlice     = errors.New("empty or invalid slice")
 )
diff --git a/adapters/postgres/internal/connection/conn.go b/adapters/postgres/internal/connection/conn.go
index dad1740..9f2410d 100644
--- a/adapters/postgres/internal/connection/conn.go
+++ b/adapters/postgres/internal/connection/conn.go
@@ -131,7 +131,9 @@ func MustGet() *sqlx.DB {
 
 // SetDatabase set current database in use
 func SetDatabase(name string) {
+	fmt.Println(name)
 	currDatabase = name
+	fmt.Println(currDatabase)
 }
 
 // GetDatabase get current database in use
diff --git a/adapters/postgres/postgres.go b/adapters/postgres/postgres.go
index cca3fd0..3ae3c56 100644
--- a/adapters/postgres/postgres.go
+++ b/adapters/postgres/postgres.go
@@ -315,8 +315,13 @@ func (adapter *Postgres) ReturningByRequest(r *http.Request) (returningSyntax st
 	return
 }
 
-func sliceToJSONList(ifaceSlice interface{}) (returnValue string) {
+func sliceToJSONList(ifaceSlice interface{}) (returnValue string, err error) {
     v := reflect.ValueOf(ifaceSlice)
+
+	if v.Kind() == 0 {
+		return "[]", ErrEmptyOrInvalidSlice
+	}
+
 	value := make([]string, 0)
 	
     for i := 0; i < v.Len(); i++ {
@@ -366,7 +371,11 @@ func (adapter *Postgres) SetByRequest(r *http.Request, initialPlaceholderID int)
 				}
 				values = append(values, string(jsonData))
 			case reflect.Slice:
-				values = append(values, sliceToJSONList(value))
+				value, err = sliceToJSONList(value)
+				if err != nil {
+					log.Errorln(err)
+				}
+				values = append(values, value)
 			default:
 				values = append(values, value)
 		}
diff --git a/adapters/postgres/postgres_test.go b/adapters/postgres/postgres_test.go
index 04aa11e..a03bf42 100644
--- a/adapters/postgres/postgres_test.go
+++ b/adapters/postgres/postgres_test.go
@@ -1983,3 +1983,31 @@ func newScannerMock(t *testing.T) (sc adapters.Scanner) {
 	}
 	return
 }
+
+func TestSliceToJSONList(t *testing.T) {
+	var i interface{}
+	var testCases = []struct {
+		description    string
+		body           interface{}
+		expectedValue  string
+		err            error
+	}{
+		{"String slice", []string{"one","two","three"}, `["one", "two", "three"]`, nil},
+		{"Integer slice", []int{1,2,3}, `[1, 2, 3]`, nil},
+		{"Interface error", i, `[]`, ErrEmptyOrInvalidSlice},
+	}
+
+	for _, tc := range testCases {
+		t.Log(tc.description)
+
+		value, err := sliceToJSONList(tc.body)
+
+		if !strings.Contains(tc.expectedValue, value) {
+			t.Errorf("expected %s in %s", value, tc.expectedValue)
+		}
+
+		if err != tc.err {
+			t.Errorf("expected %s in %s", err, tc.err)
+		}
+	}
+}
\ No newline at end of file
diff --git a/config/config.go b/config/config.go
index 7edb03a..433d11d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -44,6 +44,14 @@ type AccessConf struct {
 	Tables      []TablesConf
 }
 
+// SensitiveConf (sensitive data) informations
+type SensitiveConf struct {
+	DisableAll      bool
+	DatabaseListing bool
+	SchemaListing   bool
+	TablesListing   bool
+}
+
 // Prest basic config
 type Prest struct {
 	AuthEnabled          bool
@@ -91,6 +99,7 @@ type Prest struct {
 	HTTPSKey             string
 	Cache                Cache
 	PluginPath           string
+	SensitiveConf        SensitiveConf
 }
 
 var (
@@ -142,6 +151,10 @@ func viperCfg() {
 	viper.SetDefault("https.mode", false)
 	viper.SetDefault("https.cert", "/etc/certs/cert.crt")
 	viper.SetDefault("https.key", "/etc/certs/cert.key")
+	viper.SetDefault("sensitive.disableall", false)
+	viper.SetDefault("sensitive.tables", false)
+	viper.SetDefault("sensitive.schemas", false)
+	viper.SetDefault("sensitive.databases", false)
 	viper.SetDefault("cache.enabled", false)
 	viper.SetDefault("cache.time", 10)
 	viper.SetDefault("cache.storagepath", "./")
@@ -231,6 +244,10 @@ func Parse(cfg *Prest) (err error) {
 	cfg.Cache.Time = viper.GetInt("cache.time")
 	cfg.Cache.StoragePath = viper.GetString("cache.storagepath")
 	cfg.Cache.SufixFile = viper.GetString("cache.sufixfile")
+	cfg.SensitiveConf.DisableAll = viper.GetBool("sensitive.disableall")
+	cfg.SensitiveConf.TablesListing = viper.GetBool("sensitive.tables")
+	cfg.SensitiveConf.SchemaListing = viper.GetBool("sensitive.schemas")
+	cfg.SensitiveConf.DatabaseListing = viper.GetBool("sensitive.databases")
 	var cacheendpoints []CacheEndpoint
 	err = viper.UnmarshalKey("cache.endpoints", &cacheendpoints)
 	if err != nil {
diff --git a/controllers/databases.go b/controllers/databases.go
index 932d954..2e30256 100644
--- a/controllers/databases.go
+++ b/controllers/databases.go
@@ -10,6 +10,12 @@ import (
 
 // GetDatabases list all (or filter) databases
 func GetDatabases(w http.ResponseWriter, r *http.Request) {
+	if config.PrestConf.SensitiveConf.DisableAll || config.PrestConf.SensitiveConf.DatabaseListing {
+		err := fmt.Errorf("not authorized to list databases")
+		http.Error(w, err.Error(), http.StatusUnauthorized)
+		return
+	}
+
 	requestWhere, values, err := config.PrestConf.Adapter.WhereByRequest(r, 1)
 	if err != nil {
 		http.Error(w, err.Error(), http.StatusBadRequest)
diff --git a/controllers/databases_test.go b/controllers/databases_test.go
index 41f688f..289df72 100644
--- a/controllers/databases_test.go
+++ b/controllers/databases_test.go
@@ -44,3 +44,29 @@ func TestGetDatabases(t *testing.T) {
 		testutils.DoRequest(t, server.URL+tc.url, nil, tc.method, tc.status, "GetDatabases")
 	}
 }
+
+func TestGetDatabasesWithDisableAll(t *testing.T) {
+	config.Load()
+
+	config.PrestConf.SensitiveConf.DisableAll = true
+
+	router := mux.NewRouter()
+	router.HandleFunc("/databases", GetDatabases).Methods("GET")
+	server := httptest.NewServer(router)
+	defer server.Close()
+
+	testutils.DoRequest(t, server.URL+"/databases", nil, "GET", 401, "GetDatabases")
+}
+
+func TestGetDatabasesWithDisableDatabaseListing(t *testing.T) {
+	config.Load()
+
+	config.PrestConf.SensitiveConf.DatabaseListing = true
+
+	router := mux.NewRouter()
+	router.HandleFunc("/databases", GetDatabases).Methods("GET")
+	server := httptest.NewServer(router)
+	defer server.Close()
+
+	testutils.DoRequest(t, server.URL+"/databases", nil, "GET", 401, "GetDatabases")
+}
diff --git a/controllers/schemas.go b/controllers/schemas.go
index 65f39b8..e536342 100644
--- a/controllers/schemas.go
+++ b/controllers/schemas.go
@@ -10,6 +10,12 @@ import (
 
 // GetSchemas list all (or filter) schemas
 func GetSchemas(w http.ResponseWriter, r *http.Request) {
+	if config.PrestConf.SensitiveConf.DisableAll || config.PrestConf.SensitiveConf.SchemaListing {
+		err := fmt.Errorf("not authorized to list schemas")
+		http.Error(w, err.Error(), http.StatusUnauthorized)
+		return
+	}
+
 	requestWhere, values, err := config.PrestConf.Adapter.WhereByRequest(r, 1)
 	if err != nil {
 		http.Error(w, err.Error(), http.StatusBadRequest)
diff --git a/controllers/schemas_test.go b/controllers/schemas_test.go
index b0a8fd7..f566835 100644
--- a/controllers/schemas_test.go
+++ b/controllers/schemas_test.go
@@ -72,3 +72,29 @@ func TestVersionDependentGetSchemas(t *testing.T) {
 	}
 
 }
+
+func TestGetSchemasWithDisableAll(t *testing.T) {
+	config.Load()
+
+	config.PrestConf.SensitiveConf.DisableAll = true
+
+	router := mux.NewRouter()
+	router.HandleFunc("/schemas", GetSchemas).Methods("GET")
+	server := httptest.NewServer(router)
+	defer server.Close()
+
+	testutils.DoRequest(t, server.URL+"/schemas", nil, "GET", 401, "GetSchemas")
+}
+
+// func TestGetSchemasWithDisableSchemaListing(t *testing.T) {
+// 	config.Load()
+
+// 	config.PrestConf.SensitiveConf.SchemaListing = true
+
+// 	router := mux.NewRouter()
+// 	router.HandleFunc("/schemas", GetSchemas).Methods("GET")
+// 	server := httptest.NewServer(router)
+// 	defer server.Close()
+
+// 	testutils.DoRequest(t, server.URL+"/schemas", nil, "GET", 401, "GetSchemas")
+// }
diff --git a/controllers/sql.go b/controllers/sql.go
index 039145e..26a5830 100644
--- a/controllers/sql.go
+++ b/controllers/sql.go
@@ -14,29 +14,37 @@ import (
 
 // ExecuteScriptQuery is a function to execute and return result of script query
 func ExecuteScriptQuery(rq *http.Request, queriesPath string, script string) ([]byte, error) {
+	fmt.Println("Aqui 1")
+	fmt.Println(config.PrestConf.PGDatabase)
+	fmt.Println(rq.Method)
+	fmt.Println(queriesPath)
+	fmt.Println(script)
+	fmt.Println(config.PrestConf.Adapter)
+	fmt.Println(config.PrestConf.SensitiveConf)
+	fmt.Println("Aqui 1 22")
 	config.PrestConf.Adapter.SetDatabase(config.PrestConf.PGDatabase)
+	fmt.Println("Aqui 2")
 	sqlPath, err := config.PrestConf.Adapter.GetScript(rq.Method, queriesPath, script)
 	if err != nil {
 		err = fmt.Errorf("could not get script %s/%s, %v", queriesPath, script, err)
 		return nil, err
 	}
-
 	templateData := make(map[string]interface{})
 	extractHeaders(rq, templateData)
 	extractQueryParameters(rq, templateData)
-
+	fmt.Println("Aqui 3")
 	sql, values, err := config.PrestConf.Adapter.ParseScript(sqlPath, templateData)
 	if err != nil {
 		err = fmt.Errorf("could not parse script %s/%s, %v", queriesPath, script, err)
 		return nil, err
 	}
-
+	fmt.Println("Aqui 4")
 	sc := config.PrestConf.Adapter.ExecuteScriptsCtx(rq.Context(), rq.Method, sql, values)
 	if sc.Err() != nil {
 		err = fmt.Errorf("could not execute sql %v, %s", sc.Err(), sql)
 		return nil, err
 	}
-
+	fmt.Println("Aqui 5")
 	return sc.Bytes(), nil
 }
 
diff --git a/controllers/sql_test.go b/controllers/sql_test.go
index 9bc6b67..245c84b 100644
--- a/controllers/sql_test.go
+++ b/controllers/sql_test.go
@@ -2,6 +2,7 @@
 package controllers
 
 import (
+	"fmt"
 	"net/http"
 	"net/http/httptest"
 	"os"
@@ -15,10 +16,13 @@ import (
 )
 
 func TestExecuteScriptQuery(t *testing.T) {
+	config.Load()
 	r := mux.NewRouter()
 	r.HandleFunc("/testing/script-get/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		resp, err := ExecuteScriptQuery(r, "fulltable", "get_all")
+		fmt.Println("Entrou 1")
 		if err != nil {
+			fmt.Println(err.Error())
 			http.Error(w, err.Error(), http.StatusBadRequest)
 		}
 		w.Write(resp)
@@ -26,7 +30,9 @@ func TestExecuteScriptQuery(t *testing.T) {
 
 	r.HandleFunc("/testing/script-post/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		resp, err := ExecuteScriptQuery(r, "fulltable", "write_all")
+		fmt.Println("Entrou 2")
 		if err != nil {
+			fmt.Println(err.Error())
 			http.Error(w, err.Error(), http.StatusBadRequest)
 		}
 		w.Write(resp)
diff --git a/controllers/tables.go b/controllers/tables.go
index 432bd43..9925256 100644
--- a/controllers/tables.go
+++ b/controllers/tables.go
@@ -18,6 +18,12 @@ import (
 
 // GetTables list all (or filter) tables
 func GetTables(w http.ResponseWriter, r *http.Request) {
+	if config.PrestConf.SensitiveConf.DisableAll || config.PrestConf.SensitiveConf.TablesListing {
+		err := fmt.Errorf("not authorized to list tables")
+		http.Error(w, err.Error(), http.StatusUnauthorized)
+		return
+	}
+
 	requestWhere, values, err := config.PrestConf.Adapter.WhereByRequest(r, 1)
 	if err != nil {
 		err = fmt.Errorf("could not perform WhereByRequest: %v", err)
@@ -57,6 +63,12 @@ func GetTables(w http.ResponseWriter, r *http.Request) {
 
 // GetTablesByDatabaseAndSchema list all (or filter) tables based on database and schema
 func GetTablesByDatabaseAndSchema(w http.ResponseWriter, r *http.Request) {
+	// if config.PrestConf.SensitiveConf.DisableAll || config.PrestConf.SensitiveConf.TablesListing {
+	// 	err := fmt.Errorf("not authorized to list tables")
+	// 	http.Error(w, err.Error(), http.StatusUnauthorized)
+	// 	return
+	// }
+
 	vars := mux.Vars(r)
 	database := vars["database"]
 	schema := vars["schema"]

@cuducos
Copy link

cuducos commented Nov 28, 2022

- this was here
+ now this is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment