mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: add output matcher
This commit is contained in:
1 parent
9eb08b45f4
commit
cb26e1dcb0
2 files changed
+14
No files matched your search
@@ -40,6 +40,12 @@ export class PwdMatcher implements Matcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class OutputMatcher extends PatternMatcher implements Matcher {
|
||||||
|
match(command: Partial<Command>): boolean {
|
||||||
|
return command.output ? this.test(command.output.trim()) : false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICondition {
|
export interface ICondition {
|
||||||
command?: string
|
command?: string
|
||||||
output?: string
|
output?: string
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
CommandMatcher,
|
CommandMatcher,
|
||||||
ErrorMatcher,
|
ErrorMatcher,
|
||||||
PwdMatcher,
|
PwdMatcher,
|
||||||
|
OutputMatcher,
|
||||||
Condition,
|
Condition,
|
||||||
} from '../src/condition'
|
} from '../src/condition'
|
||||||
import { Command } from '../src/command'
|
import { Command } from '../src/command'
|
||||||
@@ -63,6 +64,13 @@ test('pwd matcher', () => {
|
|||||||
expect(matcher.match({ pwd: '/var/home/user' })).toBe(false)
|
expect(matcher.match({ pwd: '/var/home/user' })).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('output matcher', () => {
|
||||||
|
const matcher = new OutputMatcher('^start$')
|
||||||
|
expect(matcher.match({ output: 'start' })).toBe(true)
|
||||||
|
expect(matcher.match({ output: 'start1' })).toBe(false)
|
||||||
|
expect(matcher.match({ output: 'start\n' })).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
// test('condition match', () => {
|
// test('condition match', () => {
|
||||||
// const condition = new Condition({
|
// const condition = new Condition({
|
||||||
// command: '^echo start$',
|
// command: '^echo start$',
|
||||||
|
|||||||
Reference in new issue
Block a user