50 |
50 |
51 static char *pg_connstr = "postgresql://localhost/test1"; |
51 static char *pg_connstr = "postgresql://localhost/test1"; |
52 static int abort_pg_tests = 0; |
52 static int abort_pg_tests = 0; |
53 static PGconn *test_connection; |
53 static PGconn *test_connection; |
54 static ResourceData resdata; |
54 static ResourceData resdata; |
|
55 static PgRepository test_repo; |
55 |
56 |
56 void debug_print_resources(void) { |
57 void debug_print_resources(void) { |
57 PGresult *result = PQexec(test_connection, "select * from Resource;"); |
58 PGresult *result = PQexec(test_connection, "select * from Resource;"); |
58 int n = PQntuples(result); |
59 int n = PQntuples(result); |
59 printf("\nntuples: %d\n-----------------------------------------------\n", n); |
60 printf("\nntuples: %d\n-----------------------------------------------\n", n); |
65 printf("%10s %10s %s\n", res_id, parent_id, nodename); |
66 printf("%10s %10s %s\n", res_id, parent_id, nodename); |
66 } |
67 } |
67 printf("\n"); |
68 printf("\n"); |
68 } |
69 } |
69 |
70 |
|
71 static void test_root_lookup(void) { |
|
72 memset(&test_repo, 0, sizeof(PgRepository)); |
|
73 |
|
74 int64_t root_id = -1; |
|
75 int err = pg_lookup_root(&resdata, "root", &root_id); |
|
76 test_repo.root_resource_id = root_id; |
|
77 |
|
78 if(err || root_id < 0) { |
|
79 abort_pg_tests = 1; |
|
80 } |
|
81 } |
70 |
82 |
71 void register_pg_tests(int argc, char **argv, UcxTestSuite *suite) { |
83 void register_pg_tests(int argc, char **argv, UcxTestSuite *suite) { |
72 |
84 |
73 test_connection = PQconnectdb(pg_connstr); |
85 test_connection = PQconnectdb(pg_connstr); |
74 if(!test_connection) { |
86 if(!test_connection) { |
77 |
89 |
78 if(PQstatus(test_connection) != CONNECTION_OK) { |
90 if(PQstatus(test_connection) != CONNECTION_OK) { |
79 abort_pg_tests = 1; |
91 abort_pg_tests = 1; |
80 } |
92 } |
81 |
93 |
|
94 resdata.data = test_connection; |
|
95 test_root_lookup(); |
|
96 |
82 ucx_test_register(suite, test_pg_conn); |
97 ucx_test_register(suite, test_pg_conn); |
83 if(!abort_pg_tests) { |
98 if(!abort_pg_tests) { |
84 resdata.data = test_connection; |
99 ucx_test_register(suite, test_pg_lookup_root); |
85 |
100 |
86 ucx_test_register(suite, test_pg_vfs_open); |
101 ucx_test_register(suite, test_pg_vfs_open); |
87 ucx_test_register(suite, test_pg_vfs_io); |
102 ucx_test_register(suite, test_pg_vfs_io); |
88 ucx_test_register(suite, test_pg_vfs_stat); |
103 ucx_test_register(suite, test_pg_vfs_stat); |
89 ucx_test_register(suite, test_pg_vfs_mkdir); |
104 ucx_test_register(suite, test_pg_vfs_mkdir); |
228 } |
243 } |
229 |
244 |
230 UCX_TEST_END; |
245 UCX_TEST_END; |
231 } |
246 } |
232 |
247 |
233 |
248 UCX_TEST(test_pg_lookup_root) { |
234 static VFS* create_test_pgvfs(Session *sn, Request *rq) { |
249 UCX_TEST_BEGIN; |
235 return pg_vfs_create_from_resourcedata(sn, rq, &resdata); |
250 |
|
251 // test already done in test_root_lookup() |
|
252 UCX_TEST_ASSERT(!abort_pg_tests, "Lookup failed"); |
|
253 |
|
254 UCX_TEST_END; |
|
255 } |
|
256 |
|
257 |
|
258 static VFS* create_test_pgvfs(Session *sn, Request *rq) { |
|
259 return pg_vfs_create_from_resourcedata(sn, rq, &test_repo, &resdata); |
236 } |
260 } |
237 |
261 |
238 |
262 |
239 UCX_TEST(test_pg_vfs_open) { |
263 UCX_TEST(test_pg_vfs_open) { |
240 Session *sn = testutil_session(); |
264 Session *sn = testutil_session(); |
479 |
503 |
480 /* ----------------------------- WebDAV tests ----------------------------- */ |
504 /* ----------------------------- WebDAV tests ----------------------------- */ |
481 |
505 |
482 |
506 |
483 static WebdavBackend* create_test_pgdav(Session *sn, Request *rq) { |
507 static WebdavBackend* create_test_pgdav(Session *sn, Request *rq) { |
484 return pg_webdav_create_from_resdata(sn, rq, &resdata); |
508 return pg_webdav_create_from_resdata(sn, rq, &test_repo, &resdata); |
485 } |
509 } |
486 |
510 |
487 UCX_TEST(test_pg_webdav_create_from_resdata) { |
511 UCX_TEST(test_pg_webdav_create_from_resdata) { |
488 Session *sn = testutil_session(); |
512 Session *sn = testutil_session(); |
489 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
513 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |