forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch-buffer.ts
More file actions
26 lines (21 loc) · 760 Bytes
/
Copy pathmatch-buffer.ts
File metadata and controls
26 lines (21 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher';
export function matchBuffer(channel: number, contents: string): Matcher {
return new StringBufferMatcher(channel, contents);
}
class StringBufferMatcher extends Matcher {
constructor(private channel: number, private contents: string) {
super();
}
public match(value: any): boolean {
if (value instanceof Buffer) {
const buffer = value as Buffer;
const channel: number = buffer.readInt8(0);
const contents: string = buffer.toString('utf8', 1);
return this.channel === channel && this.contents === contents;
}
return false;
}
public toString(): string {
return `buffer did not contain "${this.contents}"`;
}
}