mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: add file matcher
This commit is contained in:
1 parent
b5e20766a3
commit
d612b2d6af
4 files changed
+123
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { test, expect } from '@jest/globals'
|
||||
import { IFileExistenceChecker, FileType, FileInput } from '../src/types.js'
|
||||
import { checkFiles } from '../src/condition/FileMatcher.js'
|
||||
|
||||
class MockFileChecker implements IFileExistenceChecker {
|
||||
private files: FileInput[] = [
|
||||
{
|
||||
path: '/home/user/hello.txt',
|
||||
type: FileType.FILE,
|
||||
},
|
||||
{
|
||||
path: '/home/user/world.txt',
|
||||
type: FileType.FILE,
|
||||
},
|
||||
{
|
||||
path: '/home/user/Downloads',
|
||||
type: FileType.FOLDER,
|
||||
},
|
||||
]
|
||||
|
||||
async exists(file: FileInput): Promise<boolean> {
|
||||
return this.files.some((f) => f.path === file.path && f.type === file.type)
|
||||
}
|
||||
}
|
||||
|
||||
test('file matcher', async () => {
|
||||
const checker = new MockFileChecker()
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/hello.txt',
|
||||
type: FileType.FILE,
|
||||
exists: true,
|
||||
},
|
||||
])
|
||||
).toBe(true)
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/not-exists.txt',
|
||||
type: FileType.FILE,
|
||||
exists: true,
|
||||
},
|
||||
])
|
||||
).toBe(false)
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/not-exists.txt',
|
||||
type: FileType.FILE,
|
||||
exists: false,
|
||||
},
|
||||
])
|
||||
).toBe(true)
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/Downloads',
|
||||
type: FileType.FOLDER,
|
||||
exists: true,
|
||||
},
|
||||
])
|
||||
).toBe(true)
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/hello.txt',
|
||||
type: FileType.FILE,
|
||||
exists: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/Downloads',
|
||||
type: FileType.FOLDER,
|
||||
exists: true,
|
||||
},
|
||||
])
|
||||
).toBe(true)
|
||||
expect(
|
||||
await checkFiles(checker, [
|
||||
{
|
||||
path: '/home/user/hello.txt',
|
||||
type: FileType.FILE,
|
||||
exists: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/not-exist.txt',
|
||||
type: FileType.FILE,
|
||||
exists: true,
|
||||
},
|
||||
])
|
||||
).toBe(false)
|
||||
})
|
||||
Reference in new issue
Block a user