-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsink.mock.ts
More file actions
58 lines (45 loc) · 1.25 KB
/
sink.mock.ts
File metadata and controls
58 lines (45 loc) · 1.25 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { AppendableSink, RecoverResult } from '../src/lib/wal';
export class MockAppendableSink implements AppendableSink<string> {
private writtenItems: string[] = [];
private closed = true;
open = vi.fn((): void => {
this.closed = false;
});
append = vi.fn((input: string): void => {
this.writtenItems.push(input);
});
close = vi.fn((): void => {
this.closed = true;
});
isClosed = vi.fn((): boolean => {
return this.closed;
});
recover = vi.fn((): RecoverResult<string> => {
return {
records: [...this.writtenItems],
errors: [],
partialTail: null,
};
});
repack = vi.fn((): void => {});
encode = vi.fn((input: string): string => {
return `${input}-${this.constructor.name}-encoded`;
});
getWrittenItems = vi.fn((): string[] => {
return [...this.writtenItems];
});
}
export class MockTraceEventFileSink extends MockAppendableSink {
override recover = vi.fn((): RecoverResult<string> => {
return {
records: this.getWrittenItems(),
errors: [],
partialTail: null,
};
});
repack = vi.fn((): void => {});
finalize = vi.fn((): void => {});
getPath = vi.fn((): string => {
return '/test/tmp/profiles/default/trace.default.jsonl';
});
}