Tue, 19 Apr 2022 19:14:49 +0200
add function for registering webdav backends
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2022 Olaf Wintermann. All rights reserved. |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
31 | #include "../../util/util.h" |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
32 | #include "../../test/testutils.h" |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
33 | #include "../../public/nsapi.h" |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
34 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
35 | #include <ucx/string.h> |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
36 | #include <ucx/utils.h> |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
37 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
38 | #include "pgtest.h" |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
39 | #include "vfs.h" |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
40 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
41 | #include <libpq-fe.h> |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
42 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
43 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
44 | static char *pg_connstr = "postgresql://localhost/test1"; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
45 | static int abort_pg_tests = 0; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
46 | static PGconn *test_connection; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
47 | static ResourceData resdata; |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
49 | void debug_print_resources(void) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
50 | PGresult *result = PQexec(test_connection, "select * from Resource;"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
51 | int n = PQntuples(result); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
52 | printf("\nntuples: %d\n-----------------------------------------------\n", n); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
53 | printf("%10s %10s %s\n", "resource_id", "parent_id", "nodename"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
54 | for(int i=0;i<n;i++) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
55 | char *res_id = PQgetvalue(result, i, 0); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
56 | char *parent_id = PQgetvalue(result, i, 1); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
57 | char *nodename = PQgetvalue(result, i, 2); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
58 | printf("%10s %10s %s\n", res_id, parent_id, nodename); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
59 | } |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
60 | printf("\n"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
61 | } |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
62 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
63 | |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | void register_pg_tests(int argc, char **argv, UcxTestSuite *suite) { |
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
66 | test_connection = PQconnectdb(pg_connstr); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
67 | if(!test_connection) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
68 | abort_pg_tests = 1; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
69 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
70 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
71 | if(PQstatus(test_connection) != CONNECTION_OK) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
72 | abort_pg_tests = 1; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
73 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
74 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
75 | ucx_test_register(suite, test_pg_conn); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
76 | if(!abort_pg_tests) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
77 | resdata.data = test_connection; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
78 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
79 | ucx_test_register(suite, test_pg_vfs_open); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
80 | ucx_test_register(suite, test_pg_vfs_io); |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
81 | ucx_test_register(suite, test_pg_vfs_stat); |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
82 | ucx_test_register(suite, test_pg_vfs_mkdir); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
83 | ucx_test_register(suite, test_pg_vfs_unlink); |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
84 | ucx_test_register(suite, test_pg_vfs_rmdir); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
85 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
86 | PGresult *result = PQexec(test_connection, "BEGIN"); |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
87 | PQclear(result); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
88 | } |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | } |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
90 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
91 | UCX_TEST(test_pg_conn) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
92 | char *msg = test_connection ? PQerrorMessage(test_connection) : "no connection"; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
93 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
94 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
95 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
96 | if(abort_pg_tests) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
97 | int msglen = strlen(msg); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
98 | if(msglen > 0 && msg[msglen-1] == '\n') { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
99 | msglen--; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
100 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
101 | fprintf(stdout, "%.*s: ", msglen, msg); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
102 | UCX_TEST_ASSERT(1 == 0, "skip pg tests"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
103 | } else { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
104 | UCX_TEST_ASSERT(1 == 1, "ok"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
105 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
106 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
107 | UCX_TEST_END; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
108 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
109 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
110 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
111 | static VFS* create_test_pgvfs(Session *sn, Request *rq) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
112 | return pg_vfs_create_from_resourcedata(sn, rq, &resdata); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
113 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
114 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
115 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
116 | UCX_TEST(test_pg_vfs_open) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
117 | Session *sn = testutil_session(); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
118 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
119 | rq->vfs = create_test_pgvfs(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
120 | VFSContext *vfs = vfs_request_context(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
121 | SYS_FILE file; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
122 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
123 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
124 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
125 | file = vfs_open(vfs, "/test_notfound1", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
126 | UCX_TEST_ASSERT(!file, "/test_notfound should not exist"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
127 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
128 | file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
129 | UCX_TEST_ASSERT(file, "cannot create file 1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
130 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
131 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
132 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
133 | UCX_TEST_END; |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
134 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
135 | testutil_destroy_session(sn); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
136 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
137 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
138 | UCX_TEST(test_pg_vfs_io) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
139 | Session *sn = testutil_session(); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
140 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
141 | rq->vfs = create_test_pgvfs(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
142 | VFSContext *vfs = vfs_request_context(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
143 | SYS_FILE file; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
144 | SYS_FILE file2; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
145 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
146 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
147 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
148 | file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
149 | UCX_TEST_ASSERT(file, "cannot open file1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
150 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
151 | int w = system_fwrite(file, "test1\n", 6); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
152 | UCX_TEST_ASSERT(w == 6, "fwrite ret (1)"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
153 | w = system_fwrite(file, "2", 1); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
154 | UCX_TEST_ASSERT(w == 1, "fwrite ret (2)"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
155 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
156 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
157 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
158 | file = vfs_open(vfs, "/test_f1", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
159 | file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
160 | UCX_TEST_ASSERT(file, "cannot open file1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
161 | UCX_TEST_ASSERT(file2, "cannot open file2"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
162 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
163 | char buf[128]; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
164 | int r = system_fread(file, buf, 128); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
165 | UCX_TEST_ASSERT(r == 7, "cannot read from file1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
166 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
167 | w = system_fwrite(file2, buf, r); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
168 | UCX_TEST_ASSERT(w == 7, "cannot write to file2"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
169 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
170 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
171 | vfs_close(file2); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
172 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
173 | file2 = vfs_open(vfs, "/test_f2", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
174 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
175 | r = system_fread(file, buf, 128); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
176 | UCX_TEST_ASSERT(r == 7, "fread ret"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
177 | UCX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7), "wrong buffer content after read"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
178 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
179 | vfs_close(file2); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
180 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
181 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
182 | UCX_TEST_END; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
183 | |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
184 | testutil_destroy_session(sn); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
185 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
186 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
187 | UCX_TEST(test_pg_vfs_stat) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
188 | Session *sn = testutil_session(); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
189 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
190 | rq->vfs = create_test_pgvfs(sn, rq); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
191 | VFSContext *vfs = vfs_request_context(sn, rq); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
192 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
193 | UCX_TEST_BEGIN; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
194 | |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
195 | // testdata, content doesn't matter |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
196 | char test1[512]; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
197 | memset(test1, 'x', 512); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
198 | const int test_len1 = 200; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
199 | const int test_len2 = 432; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
200 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
201 | SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
202 | UCX_TEST_ASSERT(f1, "cannot open test_s1"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
203 | system_fwrite(f1, test1, test_len1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
204 | vfs_close(f1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
205 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
206 | SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
207 | UCX_TEST_ASSERT(f2, "cannot open test_s2"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
208 | system_fwrite(f2, test1, test_len2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
209 | vfs_close(f2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
210 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
211 | struct stat st1, st2; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
212 | int r1 = vfs_stat(vfs, "/test_s1", &st1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
213 | int r2 = vfs_stat(vfs, "/test_s2", &st2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
214 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
215 | UCX_TEST_ASSERT(r1 == 0, "stat1 failed"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
216 | UCX_TEST_ASSERT(r2 == 0, "stat2 failed"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
217 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
218 | UCX_TEST_ASSERT(st1.st_size == test_len1, "s1 wrong length"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
219 | UCX_TEST_ASSERT(st2.st_size == test_len2, "s2 wrong length"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
220 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
221 | int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
222 | UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
223 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
224 | UCX_TEST_END; |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
225 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
226 | testutil_destroy_session(sn); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
227 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
228 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
229 | UCX_TEST(test_pg_vfs_mkdir) { |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
230 | Session *sn = testutil_session(); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
231 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
232 | rq->vfs = create_test_pgvfs(sn, rq); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
233 | VFSContext *vfs = vfs_request_context(sn, rq); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
234 | |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
235 | UCX_TEST_BEGIN; |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
236 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
237 | SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
238 | UCX_TEST_ASSERT(f1 == NULL, "open should fail"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
239 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
240 | int r = vfs_mkdir(vfs, "/test_mkdir"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
241 | UCX_TEST_ASSERT(r == 0, "mkdir failed"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
242 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
243 | f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
244 | UCX_TEST_ASSERT(f1, "open failed"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
245 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
246 | r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
247 | UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
248 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
249 | UCX_TEST_END; |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
250 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
251 | testutil_destroy_session(sn); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
252 | } |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
253 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
254 | UCX_TEST(test_pg_vfs_unlink) { |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
255 | Session *sn = testutil_session(); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
256 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
257 | rq->vfs = create_test_pgvfs(sn, rq); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
258 | VFSContext *vfs = vfs_request_context(sn, rq); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
259 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
260 | UCX_TEST_BEGIN; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
261 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
262 | SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
263 | UCX_TEST_ASSERT(f1, "cannot create test file"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
264 | system_fwrite(f1, "test", 4); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
265 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
266 | PgFile *pgfile = f1->data; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
267 | Oid oid = pgfile->oid; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
268 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
269 | vfs_close(f1); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
270 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
271 | int r = vfs_unlink(vfs, "/test_unlink1"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
272 | UCX_TEST_ASSERT(r == 0, "unlink failed"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
273 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
274 | f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
275 | UCX_TEST_ASSERT(f1 == NULL, "test file not deleted"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
276 | |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
277 | PGresult *result = PQexec(test_connection, "savepoint sp;"); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
278 | PQclear(result); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
279 | int pgfd = lo_open(test_connection, oid, INV_READ); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
280 | UCX_TEST_ASSERT(pgfd < 0, "large object not deleted"); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
281 | result = PQexec(test_connection, "rollback to savepoint sp;"); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
282 | PQclear(result); |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
283 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
284 | r = vfs_unlink(vfs, "/test_unlink1"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
285 | UCX_TEST_ASSERT(r, "unlink should fail"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
286 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
287 | UCX_TEST_END; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
288 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
289 | testutil_destroy_session(sn); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
290 | } |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
291 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
292 | UCX_TEST(test_pg_vfs_rmdir) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
293 | Session *sn = testutil_session(); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
294 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
295 | rq->vfs = create_test_pgvfs(sn, rq); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
296 | VFSContext *vfs = vfs_request_context(sn, rq); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
297 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
298 | PQexec(test_connection, "delete from Resource where parent_id is not null;"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
299 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
300 | UCX_TEST_BEGIN; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
301 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
302 | int r; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
303 | SYS_FILE f1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
304 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
305 | // prepare some dirs/files |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
306 | r = vfs_mkdir(vfs, "/rmdir_test"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
307 | UCX_TEST_ASSERT(r == 0, "mkdir failed (1)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
308 | r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
309 | UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
310 | r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
311 | UCX_TEST_ASSERT(r == 0, "mkdir failed (3)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
312 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
313 | f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
314 | UCX_TEST_ASSERT(f1, "open failed"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
315 | vfs_close(f1); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
316 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
317 | // test rmdir |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
318 | r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
319 | UCX_TEST_ASSERT(r == 0, "rmdir failed");; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
320 | |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
321 | r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
322 | UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
323 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
324 | r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
325 | UCX_TEST_ASSERT(r == 0, "unlink failed"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
326 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
327 | r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
328 | UCX_TEST_ASSERT(r == 0, "rmdir failed 2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
329 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
330 | UCX_TEST_END; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
331 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
332 | testutil_destroy_session(sn); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
333 | } |