53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { mkdtemp, mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { afterEach, expect, it } from 'vitest';
|
|
import { prepareBrowserFixture } from './fixture.js';
|
|
|
|
const directories: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
directories.splice(0).map((path) => rm(path, { recursive: true, force: true }))
|
|
);
|
|
});
|
|
|
|
async function destination() {
|
|
const parent = await mkdtemp(join(tmpdir(), 'browser-fixture-test-'));
|
|
directories.push(parent);
|
|
return join(parent, 'deployment');
|
|
}
|
|
|
|
it('creates a private fictional layout while preserving container paths and secret references', async () => {
|
|
const directory = await destination();
|
|
const auth = {
|
|
secret: '${AUTH_SECRET}',
|
|
credentials: { username: 'fictional-reader', password: '${AUTH_PASSWORD}' }
|
|
};
|
|
const { configPath } = await prepareBrowserFixture(directory, {
|
|
journal: '/journal/main.journal',
|
|
auth
|
|
});
|
|
expect(JSON.parse(await readFile(configPath, 'utf8'))).toMatchObject({
|
|
journal: '/journal/main.journal',
|
|
auth
|
|
});
|
|
expect(await readFile(join(directory, '.fixture'), 'utf8')).toBe('hledger-browser-fixture\n');
|
|
expect(await readFile(join(directory, 'journal', 'main.journal'), 'utf8')).toBe(
|
|
'include parts/*.journal\n'
|
|
);
|
|
expect(await readdir(join(directory, 'data'))).toEqual([]);
|
|
expect((await stat(directory)).mode & 0o777).toBe(0o700);
|
|
expect((await stat(configPath)).mode & 0o777).toBe(0o600);
|
|
});
|
|
|
|
it('refuses an existing deployment without modifying or deleting its contents', async () => {
|
|
const directory = await destination();
|
|
await mkdir(directory);
|
|
const sentinel = join(directory, 'existing');
|
|
await writeFile(sentinel, 'leave untouched');
|
|
await expect(prepareBrowserFixture(directory)).rejects.toMatchObject({ code: 'EEXIST' });
|
|
expect(await readFile(sentinel, 'utf8')).toBe('leave untouched');
|
|
expect(await readdir(directory)).toEqual(['existing']);
|
|
});
|