创建 mock S3Client 实例(通过 prototype 伪装为 S3Client 的实例)
(overrides?: Partial<S3Client>)
| 5 | |
| 6 | /** 创建 mock S3Client 实例(通过 prototype 伪装为 S3Client 的实例) */ |
| 7 | function 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 */ |
| 22 | function createMockResponse(options: { |