From 5b0971ea8d5ebe51674beb86326515b1d83e301f Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Mon, 3 Feb 2025 15:13:14 -0500 Subject: [PATCH] feat: logrotate test --- .../__fixtures__/local/logrotate.conf | 0 .../__test__/generic-modification.spec.ts | 8 ++++++-- .../logrotate.conf.modified.snapshot.php | 12 ++++++++++++ .../modifications/patches/log-rotate.patch | 18 ++++++++++++++++++ .../modifications/sso.modification.ts | 1 - 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 api/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/local/logrotate.conf create mode 100644 api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/logrotate.conf.modified.snapshot.php create mode 100644 api/src/unraid-api/unraid-file-modifier/modifications/patches/log-rotate.patch diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/local/logrotate.conf b/api/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/local/logrotate.conf new file mode 100644 index 000000000..e69de29bb diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts index 6ba4be270..18926f498 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts @@ -10,6 +10,7 @@ import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifi import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification'; import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification'; import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification'; +import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification'; interface ModificationTestCase { ModificationClass: new (...args: ConstructorParameters) => FileModification; @@ -41,6 +42,11 @@ const testCases: ModificationTestCase[] = [ fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/auth-request.php', fileName: 'auth-request.php', }, + { + ModificationClass: LogRotateModification, + fileUrl: 'logrotate.conf', + fileName: 'logrotate.conf', + }, ]; async function testModification(testCase: ModificationTestCase) { @@ -66,8 +72,6 @@ async function testModification(testCase: ModificationTestCase) { originalContent = await readFile(path, 'utf-8'); } - expect(originalContent.length).toBeGreaterThan(0); - const logger = new Logger(); const patcher = await new testCase.ModificationClass(logger); // @ts-expect-error - Ignore for testing purposes diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/logrotate.conf.modified.snapshot.php b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/logrotate.conf.modified.snapshot.php new file mode 100644 index 000000000..ba2fcc7d5 --- /dev/null +++ b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/logrotate.conf.modified.snapshot.php @@ -0,0 +1,12 @@ + +/var/log/unraid-api/*.log { + rotate 1 + missingok + size 1M + su root root + compress + delaycompress + copytruncate + create 0640 root root +} + \ No newline at end of file diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/patches/log-rotate.patch b/api/src/unraid-api/unraid-file-modifier/modifications/patches/log-rotate.patch new file mode 100644 index 000000000..428b6874e --- /dev/null +++ b/api/src/unraid-api/unraid-file-modifier/modifications/patches/log-rotate.patch @@ -0,0 +1,18 @@ +Index: /app/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/downloaded/logrotate.conf +=================================================================== +--- /app/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/downloaded/logrotate.conf ++++ /app/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/downloaded/logrotate.conf +@@ -0,0 +1,12 @@ ++ ++/var/log/unraid-api/*.log { ++ rotate 1 ++ missingok ++ size 1M ++ su root root ++ compress ++ delaycompress ++ copytruncate ++ create 0640 root root ++} ++ +\ No newline at end of file diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts b/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts index 7fdf6338f..ef4253d26 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts @@ -1,4 +1,3 @@ -import type { Logger } from '@nestjs/common'; import { readFile } from 'node:fs/promises'; import { createPatch } from 'diff';