MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / createMockClient

Function createMockClient

packages/filesystem/s3/s3.test.ts:7–19  ·  view source on GitHub ↗

创建 mock S3Client 实例(通过 prototype 伪装为 S3Client 的实例)

(overrides?: Partial<S3Client>)

Source from the content-addressed store, hash-verified

5
6/** 创建 mock S3Client 实例(通过 prototype 伪装为 S3Client 的实例) */
7function createMockClient(overrides?: Partial<S3Client>): S3Client {
8 const mock = {
9 request: vi.fn(),
10 getEndpointUrl: vi.fn().mockReturnValue("https://s3.us-east-1.amazonaws.com"),
11 hasCustomEndpoint: vi.fn().mockReturnValue(false),
12 getRegion: vi.fn().mockReturnValue("us-east-1"),
13 isForcePathStyle: vi.fn().mockReturnValue(true),
14 ...overrides,
15 };
16 // 让 instanceof S3Client 检查通过
17 Object.setPrototypeOf(mock, S3Client.prototype);
18 return mock as unknown as S3Client;
19}
20
21/** 创建 mock Response */
22function createMockResponse(options: {

Callers 1

s3.test.tsFile · 0.70

Calls 1

fnMethod · 0.80

Tested by

no test coverage detected