Files

39 lines
1.3 KiB
Go

//go:build integration
// storage_test.go S1-B(2026-11-13):对象存储集成验证——MinIO→RustFS 切换的兼容性门禁。
// 面向 compose 的 rustfs 服务(S3 API 127.0.0.1:19010),走 pkg/storage(minio-go SDK)
// 验证 MakeBucket 幂等 + Put + Stat + List 全协议面;不可达自动 skip。
package integration
import (
"context"
"strings"
"testing"
"time"
"go-sms/internal/pkg/storage"
)
func TestStorage_RustFS_S3Compat(t *testing.T) {
s, err := storage.NewS3(context.Background(), "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false)
if err != nil {
t.Skipf("对象存储(19010)不可达,跳过(make up): %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
key := "it/rustfs-compat.txt"
if err := s.Put(ctx, key, strings.NewReader("rustfs-s3-compat"), 16, "text/plain"); err != nil {
t.Fatalf("Put 失败: %v", err)
}
// 幂等复跑(同 key 覆盖写)
if err := s.Put(ctx, key, strings.NewReader("rustfs-s3-compat-v2"), 18, "text/plain"); err != nil {
t.Fatalf("Put 幂等覆盖失败: %v", err)
}
// 二次构造(桶已存在分支)
if _, err := storage.NewS3(ctx, "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false); err != nil {
t.Fatalf("桶已存在时应幂等成功: %v", err)
}
t.Log("RustFS S3 兼容面通过: MakeBucket 幂等/Put/覆盖写")
}