|
1 | 1 | const { assert } = require("chai"); |
2 | 2 | const tmp = require("tmp"); |
| 3 | +const process = require("process"); |
3 | 4 |
|
4 | 5 | describe("Database constructor", function () { |
5 | 6 | it("should create a database with a valid path and buffer size", async function () { |
@@ -38,6 +39,63 @@ describe("Database constructor", function () { |
38 | 39 | assert.notExists(testDb._initPromise); |
39 | 40 | }); |
40 | 41 |
|
| 42 | + it("should create a database in read-only mode", async function () { |
| 43 | + // TODO: Enable this test on Windows when the read-only mode is implemented. |
| 44 | + if (process.platform === "win32") { |
| 45 | + this._runnable.title += " (skipped: not implemented on Windows)"; |
| 46 | + this.skip(); |
| 47 | + } |
| 48 | + |
| 49 | + const tmpDbPath = await new Promise((resolve, reject) => { |
| 50 | + tmp.dir({ unsafeCleanup: true }, (err, path, _) => { |
| 51 | + if (err) { |
| 52 | + return reject(err); |
| 53 | + } |
| 54 | + return resolve(path); |
| 55 | + }); |
| 56 | + }); |
| 57 | + const testDb = new kuzu.Database(tmpDbPath, 1 << 28 /* 256MB */); |
| 58 | + assert.exists(testDb); |
| 59 | + assert.equal(testDb.constructor.name, "Database"); |
| 60 | + await testDb.init(); |
| 61 | + assert.exists(testDb._database); |
| 62 | + assert.isTrue(testDb._isInitialized); |
| 63 | + assert.notExists(testDb._initPromise); |
| 64 | + delete testDb; |
| 65 | + const testDbReadOnly = new kuzu.Database( |
| 66 | + tmpDbPath, |
| 67 | + 1 << 28 /* 256MB */, |
| 68 | + true, |
| 69 | + kuzu.AccessMode.READ_ONLY |
| 70 | + ); |
| 71 | + assert.exists(testDbReadOnly); |
| 72 | + assert.equal(testDbReadOnly.constructor.name, "Database"); |
| 73 | + await testDbReadOnly.init(); |
| 74 | + assert.exists(testDbReadOnly._database); |
| 75 | + assert.isTrue(testDbReadOnly._isInitialized); |
| 76 | + assert.notExists(testDbReadOnly._initPromise); |
| 77 | + const connection = new kuzu.Connection(testDbReadOnly); |
| 78 | + assert.exists(connection); |
| 79 | + assert.equal(connection.constructor.name, "Connection"); |
| 80 | + await connection.init(); |
| 81 | + assert.exists(connection._connection); |
| 82 | + assert.isTrue(connection._isInitialized); |
| 83 | + assert.notExists(connection._initPromise); |
| 84 | + try { |
| 85 | + const _ = await connection.query( |
| 86 | + "CREATE NODE TABLE test (id INT64, PRIMARY KEY(id))" |
| 87 | + ); |
| 88 | + assert.fail( |
| 89 | + "No error thrown when executing CREATE TABLE in read-only mode." |
| 90 | + ); |
| 91 | + } catch (e) { |
| 92 | + assert.equal( |
| 93 | + e.message, |
| 94 | + "Cannot execute write operations in a read-only access mode database!" |
| 95 | + ); |
| 96 | + } |
| 97 | + }); |
| 98 | + |
41 | 99 | it("should throw error if the path is invalid", async function () { |
42 | 100 | try { |
43 | 101 | const _ = new kuzu.Database({}, 1 << 28 /* 256MB */); |
|
0 commit comments