|
1 | | -import type { Sink } from '../src/lib/sink-source.type'; |
| 1 | +import { WriteAheadLogFile } from '../src/lib/profiler/wal.js'; |
| 2 | +import type { Codec } from '../src/lib/types.js'; |
2 | 3 |
|
3 | | -export class MockFileSink implements Sink<string, string> { |
4 | | - setPath: (filePath: string) => void; |
5 | | - getPath: () => string; |
| 4 | +export class MockFileSink implements WriteAheadLogFile<string> { |
6 | 5 | private writtenItems: string[] = []; |
7 | 6 | private closed = false; |
8 | 7 |
|
| 8 | + constructor(options?: { file?: string; codec?: Codec<string> }) { |
| 9 | + const file = options?.file || '/tmp/mock-sink.log'; |
| 10 | + const codec = options?.codec || { |
| 11 | + encode: (input: string) => input, |
| 12 | + decode: (data: string) => data, |
| 13 | + }; |
| 14 | + } |
| 15 | + |
| 16 | + #fd: number | null = null; |
| 17 | + |
| 18 | + get path(): string { |
| 19 | + return '/tmp/mock-sink.log'; |
| 20 | + } |
| 21 | + |
| 22 | + getPath(): string { |
| 23 | + return this.path; |
| 24 | + } |
| 25 | + |
9 | 26 | open(): void { |
10 | | - this.closed = false; |
| 27 | + this.#fd = 1; // Mock file descriptor |
11 | 28 | } |
12 | 29 |
|
13 | | - write(input: string): void { |
14 | | - this.writtenItems.push(input); |
| 30 | + append(v: string): void { |
| 31 | + this.writtenItems.push(v); |
15 | 32 | } |
16 | 33 |
|
17 | 34 | close(): void { |
| 35 | + this.#fd = null; |
18 | 36 | this.closed = true; |
19 | 37 | } |
20 | 38 |
|
21 | 39 | isClosed(): boolean { |
22 | | - return this.closed; |
| 40 | + return this.#fd === null; |
| 41 | + } |
| 42 | + |
| 43 | + recover(): any { |
| 44 | + return { |
| 45 | + records: this.writtenItems, |
| 46 | + errors: [], |
| 47 | + partialTail: null, |
| 48 | + }; |
23 | 49 | } |
24 | 50 |
|
25 | | - encode(input: string): string { |
26 | | - return `${input}-${this.constructor.name}-encoded`; |
| 51 | + repack(): void { |
| 52 | + // Mock implementation - do nothing |
27 | 53 | } |
28 | 54 |
|
29 | 55 | getWrittenItems(): string[] { |
|
0 commit comments