test(apps.service): copy file and replace variables coverage
This commit is contained in:
parent
ead2f23fa8
commit
a728507882
4 changed files with 61 additions and 1 deletions
1
.github/workflows/e2e.yml
vendored
1
.github/workflows/e2e.yml
vendored
|
@ -3,6 +3,7 @@ name: E2E Tests
|
|||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches:
|
||||
- release/*
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ class FsMock {
|
|||
};
|
||||
|
||||
mkdirSync = (p: string) => {
|
||||
this.mockFiles[p] = Object.create(null);
|
||||
if (!this.mockFiles[p]) {
|
||||
this.mockFiles[p] = [];
|
||||
}
|
||||
};
|
||||
|
||||
rmSync = (p: string) => {
|
||||
|
@ -128,6 +130,18 @@ class FsMock {
|
|||
},
|
||||
writeFile: async (p: string, data: string | string[]) => {
|
||||
this.mockFiles[p] = data;
|
||||
|
||||
const dir = path.dirname(p);
|
||||
if (!this.mockFiles[dir]) {
|
||||
this.mockFiles[dir] = [];
|
||||
}
|
||||
|
||||
this.mockFiles[dir].push(path.basename(p));
|
||||
},
|
||||
mkdir: async (p: string) => {
|
||||
if (!this.mockFiles[p]) {
|
||||
this.mockFiles[p] = [];
|
||||
}
|
||||
},
|
||||
readdir: async (p: string) => {
|
||||
const files: string[] = [];
|
||||
|
@ -146,6 +160,19 @@ class FsMock {
|
|||
|
||||
return files;
|
||||
},
|
||||
lstat: async (p: string) => {
|
||||
return {
|
||||
isDirectory: () => {
|
||||
return this.mockFiles[p] instanceof Array;
|
||||
},
|
||||
};
|
||||
},
|
||||
readFile: async (p: string) => {
|
||||
return this.mockFiles[p];
|
||||
},
|
||||
copyFile: async (source: string, destination: string) => {
|
||||
this.mockFiles[destination] = this.mockFiles[source];
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -269,6 +269,7 @@ export const copyDataDir = async (id: string) => {
|
|||
};
|
||||
|
||||
const processDir = async (path: string) => {
|
||||
await fs.promises.mkdir(`/app/storage/app-data/${id}/data/${path}`, { recursive: true });
|
||||
const files = await fs.promises.readdir(`/runtipi/apps/${id}/data/${path}`);
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -239,6 +239,37 @@ describe('Install app', () => {
|
|||
// act & assert
|
||||
await expect(AppsService.installApp(appConfig.id, {})).rejects.toThrowError();
|
||||
});
|
||||
|
||||
it('should replace env variables in .templates files in data folder', async () => {
|
||||
// arrange
|
||||
const appConfig = createAppConfig({ form_fields: [{ env_variable: 'TEST', type: 'text', label: 'test', required: true }] });
|
||||
await fs.promises.writeFile(`/runtipi/apps/${appConfig.id}/data/test.txt.template`, 'test {{TEST}}');
|
||||
await fs.promises.writeFile(`/runtipi/apps/${appConfig.id}/data/test2.txt`, 'test {{TEST}}');
|
||||
|
||||
// act
|
||||
await AppsService.installApp(appConfig.id, { TEST: 'test' });
|
||||
|
||||
// assert
|
||||
const file = await fs.promises.readFile(`/app/storage/app-data/${appConfig.id}/data/test.txt`);
|
||||
const file2 = await fs.promises.readFile(`/app/storage/app-data/${appConfig.id}/data/test2.txt`);
|
||||
expect(file.toString()).toBe('test test');
|
||||
expect(file2.toString()).toBe('test {{TEST}}');
|
||||
});
|
||||
|
||||
it('should copy and replace env variables in deeply nested .templates files in data folder', async () => {
|
||||
// arrange
|
||||
const appConfig = createAppConfig({ form_fields: [{ env_variable: 'TEST', type: 'text', label: 'test', required: true }] });
|
||||
await fs.promises.mkdir(`/runtipi/apps/${appConfig.id}/data/test`);
|
||||
await fs.promises.mkdir(`/runtipi/apps/${appConfig.id}/data/test/test`);
|
||||
await fs.promises.writeFile(`/runtipi/apps/${appConfig.id}/data/test/test/test.txt.template`, 'test {{TEST}}');
|
||||
|
||||
// act
|
||||
await AppsService.installApp(appConfig.id, { TEST: 'test' });
|
||||
|
||||
// assert
|
||||
const file = await fs.promises.readFile(`/app/storage/app-data/${appConfig.id}/data/test/test/test.txt`);
|
||||
expect(file.toString()).toBe('test test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Uninstall app', () => {
|
||||
|
|
Loading…
Reference in a new issue