Improved atomicity
This commit is contained in:
1 parent
b70628264e
commit
b8b3e348e8
3 files changed
+48
-15
No files matched your search
@@ -45,7 +45,7 @@ Deno.test('DenoKVBlobService happy path', async (t) => {
|
||||
kv.close();
|
||||
});
|
||||
|
||||
Deno.test('DenoKVFileService happy path xxx ', async (t) => {
|
||||
Deno.test('DenoKVFileService happy path ', async (t) => {
|
||||
const kv = await Deno.openKv(':memory:');
|
||||
const fs: FileService = new DenoKVFileService(kv);
|
||||
const fileName1 = 'didier/file1.txt';
|
||||
@@ -54,8 +54,8 @@ Deno.test('DenoKVFileService happy path xxx ', async (t) => {
|
||||
let file2: FileMetaData | undefined;
|
||||
|
||||
await t.step('Create 2 files xyzabc', async () => {
|
||||
file1 = await fs.createFromFullContent(fileName1, 'bob le chef');
|
||||
file2 = await fs.createFromFullContent(fileName2, 'le geant vert ☀️');
|
||||
file1 = (await fs.createFromFullContent(fileName1, 'bob le chef'))!;
|
||||
file2 = (await fs.createFromFullContent(fileName2, 'le geant vert ☀️'))!;
|
||||
|
||||
assertEquals(file1.path, fileName1);
|
||||
assertEquals(file2.contentSize, 47);
|
||||
@@ -97,7 +97,7 @@ Deno.test('DenoKVFileService happy path xxx ', async (t) => {
|
||||
const newPath = 'boris/streamed-file.txt';
|
||||
|
||||
const ret = await fs.createFromReader(newPath, new StringReader('hello world 18'));
|
||||
assertEquals(ret.contentSize, 40);
|
||||
assertEquals(ret!.contentSize, 40);
|
||||
|
||||
const s = await fs.getRawContentByPath(newPath);
|
||||
assertEquals(new TextDecoder().decode(s!), 'hello world 18');
|
||||
@@ -117,6 +117,27 @@ Deno.test('DenoKVFileService happy path xxx ', async (t) => {
|
||||
kv.close();
|
||||
});
|
||||
|
||||
|
||||
Deno.test('DenoKVFileService file duplication',async (t) => {
|
||||
const kv = await Deno.openKv(':memory:');
|
||||
const fs: FileService = new DenoKVFileService(kv);
|
||||
|
||||
await t.step("Create two files with same name", async () => {
|
||||
const file1 = await fs.createFromFullContent('create/one', 'file 1');
|
||||
const file2 = await fs.createFromFullContent(file1!.path, 'file 2');
|
||||
assertEquals(file2, null);
|
||||
});
|
||||
|
||||
await t.step('Rename file to path that already exists',async () => {
|
||||
const file1 = await fs.createFromFullContent('rename/one', 'file 1');
|
||||
const file2 = await fs.createFromFullContent('rename/two', 'file 2');
|
||||
const ret = await fs.renameById(file1!.id, file2!.path);
|
||||
assertEquals(ret!.path, file1!.path) // assert file did not move
|
||||
});
|
||||
|
||||
kv.close();
|
||||
|
||||
})
|
||||
Deno.test('DenoKVFileService happy path with byte array', async (t) => {
|
||||
const kv = await Deno.openKv(':memory:');
|
||||
const fs: FileService = new DenoKVFileService(kv);
|
||||
@@ -124,8 +145,8 @@ Deno.test('DenoKVFileService happy path with byte array', async (t) => {
|
||||
const inputContent = new Uint8Array([240]);
|
||||
const file = await fs.createFromFullContent('hello', inputContent);
|
||||
|
||||
assertEquals(file.path, 'hello');
|
||||
assertEquals(file.contentSize, 27);
|
||||
assertEquals(file!.path, 'hello');
|
||||
assertEquals(file!.contentSize, 27);
|
||||
|
||||
const persistedContent = await fs.getRawContentByPath('hello');
|
||||
assertEquals(persistedContent, inputContent);
|
||||
|
||||
Reference in new issue
Block a user