Skip to content

Commit

Permalink
fix tests now
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Jan 8, 2025
1 parent 19fdfcf commit ff568fd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/controller/test/lib/testFiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { TestContext } from '../_Types.js';
import { objectsUtils as utils } from '@iobroker/db-objects-redis';

export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, context: TestContext): void {
const testName = `${context.name} ${context.adapterShortName} files: `;
Expand All @@ -10,7 +9,7 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
const fileName = 'testFile.bin';
const dataBinary = Buffer.from('1234');
// create an object of type file first
await context.adapter.setForeignObjectAsync(objId, {
await context.adapter.setForeignObject(objId, {
type: 'meta',
common: {
name: 'Files and more',
Expand Down Expand Up @@ -226,26 +225,33 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont

it(`${testName}should read empty directory`, async () => {
const objects = context.objects;
const id = `${testId}.files`;
const id = `${testId}.meta.files`;

await objects.setObject(id, {
type: 'meta',
common: { name: 'test', type: 'meta.user' },
native: {},
});

const res = await objects.readDirAsync(id, '');
expect(res).to.be.empty;
});

it(`${testName}should read empty directory with path`, async () => {
const objects = context.objects;
const id = `${testId}.files`;
const id = `${testId}.meta.files`;

const res = await objects.readDirAsync(id, 'random/path');
expect(res).to.be.empty;
});

it(`${testName}should respond with 'ERROR_NOT_FOUND' if calling readDir on a single file`, async () => {
it(`${testName}should respond with empty array if calling readDir on a single file`, async () => {
const objects = context.objects;
const fileName = 'dir/notADir.txt';

await objects.writeFileAsync(testId, fileName, 'dataInFile');
expect(objects.readDirAsync(testId, fileName)).to.be.eventually.rejectedWith(utils.ERRORS.ERROR_NOT_FOUND);
const res = await objects.readDirAsync(testId, fileName);
expect(res).to.be.empty;
});

it(`${testName}should read file and prevent path traversing`, done => {
Expand Down

0 comments on commit ff568fd

Please sign in to comment.