# @bylocico/testcontainers-rustfs 中文文档

规范地址：https://npmcn.com/package/%40bylocico/testcontainers-rustfs/

版本：1\.0\.0-beta\.1
npm 元数据更新时间：2026-05-08T00:37:33.000Z
中文译文更新时间：2026-11-08T21:26:43.633Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bylocico/testcontainers-rustfs
原文对照：https://npmcn.com/package/%40bylocico/testcontainers-rustfs/?lang=original
项目主页：https://github.com/bylocico/testcontainers-rustfs#readme
源码仓库：https://github.com/bylocico/testcontainers-rustfs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：18.2 kB，13 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：1 个
- peer 依赖：@aws-sdk/client-s3 \>=3
- 首次发布：2026-05-08T00:37:32.462Z
- 最新版本发布：2026-05-08T00:37:32.742Z
- 近 30 天下载量：3342（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 1 个）

## 中文简介

RustFS的测试容器包装器——一个用Rust书写的S3相容对象商店.

## 安装

```sh
npm install @bylocico/testcontainers-rustfs
```

也可以使用：`pnpm add @bylocico/testcontainers-rustfs`、`yarn add @bylocico/testcontainers-rustfs`、`bun add @bylocico/testcontainers-rustfs`

## README

# @bylocico/ testcontainers-rustfs (英语)

一个小 [测试容器](https://testcontainers.com/) 包装 [RustFS 红外线](https://rustfs.com/),用 Rust 书写的 S3 兼容对象商店.

软件包是故意的依赖灯光,形状像正式的TestContainers模块,因此可以上游到 [`testcontainers/testcontainers-node`](https://github.com/testcontainers/testcontainers-node) 等会.

## 版本

Npm 包版本跟踪它所瞄准的 RustFS Docker 图像版本.

譬如说, `@bylocico/testcontainers-rustfs@1.0.0-beta.1` 默认为:

```text
rustfs/rustfs:1.0.0-beta.1
```

仅用 Wrapper 的修改应该保持小幅并随下个 RustFS 目标版本在实用之处发布. 如果在 RustFS 移动前需要紧急包装修复,则发布补丁版本,并在发布注释中记录例外.

CI在拉出请求后自动运行并推出. 更新工作流程还查询了Docker Hub的进度表,找到每一个新的 semver RustFS 图像标签,按照上升顺序对每个标签进行测试,并打开一个自动并发的PR,将软件包重新瞄准最新的通过标记. 诸如 `-glibc` 被忽略用于包版本,因为它们是图像口味,而不是 RustFS 发布版本.

消费者仍然可以拉出任何有效的 RustFS 图像版本,而不等待这个包重新瞄准:

```ts
await new RustfsContainer('rustfs/rustfs:1.0.0-beta.1').start()
await new RustfsContainer('rustfs/rustfs:latest').start()
```

## 安装

```bash
npm install --save-dev @bylocico/testcontainers-rustfs @aws-sdk/client-s3
```

`@aws-sdk/client-s3` 是一种对等依赖,因为大多数消费者已经拥有其SDK版本.

## 使用量

```ts
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
import { RustfsContainer } from '@bylocico/testcontainers-rustfs'

const rustfs = await new RustfsContainer().start()

try {
  await rustfs.ensureBucket('my-bucket')

  const s3 = new S3Client({
    endpoint: rustfs.getEndpoint(),
    region: 'us-east-1',
    credentials: {
      accessKeyId: rustfs.accessKey,
      secretAccessKey: rustfs.secretKey,
    },
    forcePathStyle: true,
  })

  try {
    await s3.send(
      new PutObjectCommand({
        Bucket: 'my-bucket',
        Key: 'hello.txt',
        Body: 'world',
      }),
    )
  } finally {
    s3.destroy()
  }
} finally {
  await rustfs.stop()
}
```

## API 密码

### `new RustfsContainer(image?: string)`

创建未启动的 RustFS 容器 。 默认情况下,它使用与包版本相匹配的RustFS图像版本.

通过一个清晰的图像来测试不同的 RustFS 发布 :

```ts
new RustfsContainer('rustfs/rustfs:latest')
new RustfsContainer('rustfs/rustfs:1.0.0-beta.1')
```

### `.withCredentials(user, password)`

覆盖默认的根用户/密码字.

默认 :

```text
rustfsadmin / rustfsadmin
```

示例

```ts
const rustfs = await new RustfsContainer()
  .withCredentials('test-user', 'test-password')
  .start()
```

都一样 `GenericContainer` 通过继承,包括 `withEnvironment`, (中文(简体) ), `withCommand`,以及 `withNetwork`。 。 。 .

### `StartedRustfsContainer`

开始的容器暴露:

-   `getEndpoint(): string` - 说吧 `http://<host>:<port>` 用于 S3 API
-   `getHost(): string`
-   `getPort(): number`
-   `accessKey: string`
-   `secretKey: string`
-   `ensureBucket(name): Promise<void>`
-   `stop(): Promise<void>`

`ensureBucket()` 是天分和容忍的 `BucketAlreadyOwnedByYou` 财务报告和审定财务报表 `BucketAlreadyExists`。 。 。 .

## S3 客户端说明

使用 `getEndpoint()` 而不是硬编码端口。 测试容器映射容器端口 `9000` 到随机主机端口.

使用 AWS SDK 的路径式地址 :

```ts
forcePathStyle: true
```

虚拟托管的地址需要测试容器不提供的DNS条目.

## 发展

所需经费:

-   节点.js 18+
-   无
-   夹克

安装依赖性 :

```bash
npm install
```

运行检查 :

```bash
npm run typecheck
npm run build
npm test
```

针对特定的 RustFS 图像进行测试 :

```bash
RUSTFS_IMAGE=rustfs/rustfs:latest npm test
```

列表 RustFS 发布图像标记比软件包目标更新 :

```bash
node scripts/update-rustfs-version.mjs --list-newer
```

将软件包重新设定为特定的 RustFS 版本 :

```bash
node scripts/update-rustfs-version.mjs --version 1.0.0-beta.1
npm install --package-lock-only
```

发布前检查包内容 :

```bash
npm pack --dry-run
```

## 出版

出版由 `.github/workflows/publish.yml`。 。 。 .

仓库设置 :

1.  创建 npm 自动化令牌, 并发布访问权限到 `@bylocico/testcontainers-rustfs`。 。 。 .
2.  添加到 GitHub 寄存器 `NPM_TOKEN`。 。 。 .
3.  确保 GitHub 动作有权限为 npm 出处请求 OIDC 令牌 .

释放流量 :

1.  确认目标 RustFS 标记存在 :
    
    ```bash
    docker manifest inspect rustfs/rustfs:1.0.0-beta.1
    ```
    
2.  更新 `package.json` 财务报告和审定财务报表 `DEFAULT_RUSTFS_VERSION` 改为同一版本.
    
3.  运行 `npm install` 这样 `package-lock.json` 记录新软件包版本.
    
4.  运行 `npm run typecheck && npm run build && npm test && npm pack --dry-run`。 。 。 .
    
5.  推动 `main`。 。 。 .
    
6.  例如, 为同一版本创建 GitHub 发布 `v1.0.0-beta.1`。 。 。 .
    
7.  出版工作流程进行测试并发布 npm出处:
    
    ```bash
    npm publish --access public --provenance
    ```
    

## 上游

让公众API接近正式的Testcontainers模块样式:

-   一个容器类别延伸 `GenericContainer`
-   一个开始集装箱类扩展 `AbstractStartedContainer`
-   没有特定应用程序的依赖性
-   没有 Bylocico 或 Ema 特定的运行时间行为

今后上游对 `testcontainers/testcontainers-node` 小而可审.

## 常见问题

### @bylocico/testcontainers-rustfs 是什么？

RustFS的测试容器包装器——一个用Rust书写的S3相容对象商店\.

### 如何安装 @bylocico/testcontainers-rustfs？

在项目目录运行 npm install @bylocico/testcontainers-rustfs，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@aws-sdk/client-s3（\>=3）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @bylocico/testcontainers-rustfs 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bylocico/testcontainers-rustfs 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @bylocico/testcontainers-rustfs 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @bylocico/testcontainers-rustfs 可以商用吗？

@bylocico/testcontainers-rustfs 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @bylocico/testcontainers-rustfs 的下载量有多少？

根据 npm 官方下载统计，@bylocico/testcontainers-rustfs 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,342 次，日均约 111 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bylocico/testcontainers-rustfs 还在维护吗？

最新版本 1\.0\.0-beta\.1 发布于 2026/05/08（6 个月前）；至今共发布 1 个版本，其中过去 12 个月发布了 1 个；首次发布于 2026/05/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

