fakes3

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package fakes3 是一个内存版 S3 兼容端点,仅供测试使用(不参与二进制构建)。 它覆盖 sail serve 用到的子集:HeadObject / GetObject(Range) / PutObject / CopyObject / DeleteObject / DeleteObjects / ListObjectsV2 (含 Delimiter 与分页) / multipart 三件套,并统计各类请求次数, 便于断言「列目录不发 GetObject」这类行为约束。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Head        atomic.Int64
	Get         atomic.Int64
	Put         atomic.Int64
	List        atomic.Int64
	Delete      atomic.Int64
	DeleteBatch atomic.Int64
	Copy        atomic.Int64
	Multipart   atomic.Int64
}

Counts 记录各类请求次数。

type Object

type Object struct {
	Data        []byte
	ContentType string
	// Metadata 是用户元数据(x-amz-meta-*),键为去前缀后的小写名。
	// sail serve 的 payload 元数据判定依赖它,故 fake 端必须能往返。
	Metadata map[string]string
	ModTime  time.Time
}

Object 是一个朴素对象:1 key = 1 份完整数据。

type Server

type Server struct {
	Counts Counts

	// BatchDeleteStatus 是 FailBatchDelete 生效时返回的状态码;0 表示 500
	// (多数网关代答「不支持」的形态),测试可显式设为 501 等。
	BatchDeleteStatus atomic.Int64
	// FailBatchDeleteKeys 置真时,批量删除返回 200 但每个 key 都带 <Error>
	// ——模拟「端点可用、部分对象删不掉」的真实形态。
	FailBatchDeleteKeys atomic.Bool
	// FailBatchDelete 置真时,批量删除端点(?delete)返回 500——模拟不支持
	// DeleteObjects 的 S3 兼容服务(如某些自建网关),用于验证回退路径。
	FailBatchDelete atomic.Bool
	// DeleteDelay 是单对象删除的注入延迟,用于把并发回退与串行回退区分开:
	// 并发执行时总耗时应接近单个延迟而非 N 倍。
	DeleteDelay atomic.Int64
	// CopyDelay 是单对象复制的注入延迟,用途同 DeleteDelay。
	CopyDelay atomic.Int64
	// contains filtered or unexported fields
}

Server 是内存 S3 端点。

func New

func New() *Server

New 启动一个内存 S3 端点,调用方负责 Close。

func (*Server) Close

func (s *Server) Close()

Close 关闭端点。

func (*Server) Get

func (s *Server) Get(bucket, key string) (Object, bool)

Get 读取一个对象(测试断言用)。

func (*Server) Keys

func (s *Server) Keys(bucket string) []string

Keys 列出所有 key(测试断言用)。

func (*Server) Put

func (s *Server) Put(bucket, key string, data []byte, contentType string)

Put 直接写入一个对象(测试夹具用)。

func (*Server) PutWithMetadata

func (s *Server) PutWithMetadata(bucket, key string, data []byte, contentType string, md map[string]string)

PutWithMetadata 写入一个带用户元数据的对象(测试夹具用)。

func (*Server) URL

func (s *Server) URL() string

URL 是端点地址,可直接作为 endpoint 配置。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL