test: Initialize empty pods when testing quota

Another attempt to help fix random CI integration test failures
This commit is contained in:
Joachim Van Herwegen 2023-10-05 11:04:01 +02:00
parent 71e55690f3
commit 44f731d7e7
3 changed files with 21 additions and 23 deletions

View File

@ -1,9 +1,8 @@
import { promises as fsPromises } from 'fs';
import type { Stats } from 'fs';
import fetch from 'cross-fetch';
import type { Response } from 'cross-fetch';
import { ensureDir, pathExists } from 'fs-extra';
import { joinFilePath, joinUrl } from '../../src';
import { ensureDir, pathExists, stat } from 'fs-extra';
import { joinUrl } from '../../src';
import type { App } from '../../src';
import { getPort } from '../util/Util';
import { getDefaultVariables, getTestConfigPath, getTestFolder, instantiateFromConfig, removeFolder } from './Config';
@ -45,23 +44,6 @@ async function registerTestPods(baseUrl: string, pods: string[]): Promise<void>
}
}
/* We just want a container with the correct metadata, everything else can be removed */
async function clearInitialFiles(rootFilePath: string, pods: string[]): Promise<void> {
for (const pod of pods) {
const fileList = await fsPromises.readdir(joinFilePath(rootFilePath, pod));
for (const file of fileList) {
if (file !== '.meta') {
const path = joinFilePath(rootFilePath, pod, file);
if ((await fsPromises.stat(path)).isDirectory()) {
await fsPromises.rm(path, { recursive: true });
} else {
await fsPromises.unlink(path);
}
}
}
}
}
describe('A quota server', (): void => {
// The allowed quota depends on what filesystem/OS you are using.
// For example: an empty folder is reported as
@ -74,7 +56,7 @@ describe('A quota server', (): void => {
// We want to use an empty folder as on APFS/Mac folder sizes vary a lot
const tempFolder = getTestFolder('quota-temp');
await ensureDir(tempFolder);
folderSizeTest = await fsPromises.stat(tempFolder);
folderSizeTest = await stat(tempFolder);
await removeFolder(tempFolder);
});
const podName1 = 'arthur';
@ -108,7 +90,6 @@ describe('A quota server', (): void => {
// Initialize 2 pods
await registerTestPods(baseUrl, [ podName1, podName2 ]);
await clearInitialFiles(rootFilePath, [ podName1, podName2 ]);
});
afterAll(async(): Promise<void> => {
@ -194,7 +175,6 @@ describe('A quota server', (): void => {
// Initialize 2 pods
await registerTestPods(baseUrl, [ podName1, podName2 ]);
await clearInitialFiles(rootFilePath, [ podName1, podName2 ]);
});
afterAll(async(): Promise<void> => {

View File

@ -54,6 +54,15 @@
"@type": "FileSizeReporter",
"ignoreFolders": [ "^/\\.internal$" ]
},
{
"comment": "Use an empty pod for quota tests",
"@type": "Override",
"overrideInstance": { "@id": "urn:solid-server:default:PodResourcesGenerator" },
"overrideParameters": {
"@type": "StaticFolderGenerator",
"templateFolder": "@css:templates/root/empty"
}
},
{
"@id": "urn:solid-server:test:Instances",
"@type": "RecordObject",

View File

@ -49,6 +49,15 @@
},
"limit_unit": "bytes"
},
{
"comment": "Use an empty pod for quota tests",
"@type": "Override",
"overrideInstance": { "@id": "urn:solid-server:default:PodResourcesGenerator" },
"overrideParameters": {
"@type": "StaticFolderGenerator",
"templateFolder": "@css:templates/root/empty"
}
},
{
"@id": "urn:solid-server:test:Instances",
"@type": "RecordObject",