add pg stat tests webdav

Sun, 17 Apr 2022 12:04:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 17 Apr 2022 12:04:41 +0200
branch
webdav
changeset 293
d3899857a81d
parent 292
7c31bcd5b4be
child 294
277a5896a2ec

add pg stat tests

src/server/plugins/postgresql/pgtest.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/pgtest.c	Sun Apr 17 11:51:37 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.c	Sun Apr 17 12:04:41 2022 +0200
@@ -63,8 +63,10 @@
         
         ucx_test_register(suite, test_pg_vfs_open);
         ucx_test_register(suite, test_pg_vfs_io);
+        ucx_test_register(suite, test_pg_vfs_stat);
         
         PGresult *result = PQexec(test_connection, "BEGIN");
+        PQclear(result);
     }
 }
 
@@ -166,11 +168,38 @@
     Request *rq = testutil_request(sn->pool, "PUT", "/");
     rq->vfs = create_test_pgvfs(sn, rq);
     VFSContext *vfs = vfs_request_context(sn, rq);
-    SYS_FILE file;
-    SYS_FILE file2;
     
     UCX_TEST_BEGIN;
     
+    // testdata, content doesn't matter
+    char test1[512];
+    memset(test1, 'x', 512);
+    const int test_len1 = 200;
+    const int test_len2 = 432;
+    
+    SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT);
+    UCX_TEST_ASSERT(f1, "cannot open test_s1");
+    system_fwrite(f1, test1, test_len1);
+    vfs_close(f1);
+    
+    SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT);
+    UCX_TEST_ASSERT(f2, "cannot open test_s2");
+    system_fwrite(f2, test1, test_len2);
+    vfs_close(f2);
+    
+    struct stat st1, st2;
+    int r1 = vfs_stat(vfs, "/test_s1", &st1);
+    int r2 = vfs_stat(vfs, "/test_s2", &st2);
+    
+    UCX_TEST_ASSERT(r1 == 0, "stat1 failed");
+    UCX_TEST_ASSERT(r2 == 0, "stat2 failed");
+    
+    UCX_TEST_ASSERT(st1.st_size == test_len1, "s1 wrong length");
+    UCX_TEST_ASSERT(st2.st_size == test_len2, "s2 wrong length");
+    
+    int testfail = vfs_stat(vfs, "/test_stat_fail", &st1);
+    UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail");
+    
     UCX_TEST_END;
 }
 

mercurial