feat(config): add MinIO object storage configuration

Add MinioConfig struct with connection, bucket, chunk size, and session TTL settings.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-15 09:22:18 +08:00
parent a65c8762af
commit 44895214d4
3 changed files with 177 additions and 7 deletions

View File

@@ -254,3 +254,135 @@ log:
t.Errorf("Log.FilePath = %q, want %q", cfg.Log.FilePath, "/var/log/app.log")
}
}
func TestLoadWithMinioConfig(t *testing.T) {
content := []byte(`server_port: "9090"
slurm_api_url: "http://slurm.example.com:6820"
slurm_user_name: "admin"
slurm_jwt_key_path: "/etc/slurm/jwt.key"
mysql_dsn: "user:pass@tcp(10.0.0.1:3306)/testdb?parseTime=true"
minio:
endpoint: "minio.example.com:9000"
access_key: "myaccesskey"
secret_key: "mysecretkey"
bucket: "test-bucket"
use_ssl: true
chunk_size: 33554432
max_file_size: 107374182400
min_chunk_size: 10485760
session_ttl: 24
`)
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
if err := os.WriteFile(path, content, 0644); err != nil {
t.Fatalf("write temp config: %v", err)
}
cfg, err := Load(path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Minio.Endpoint != "minio.example.com:9000" {
t.Errorf("Minio.Endpoint = %q, want %q", cfg.Minio.Endpoint, "minio.example.com:9000")
}
if cfg.Minio.AccessKey != "myaccesskey" {
t.Errorf("Minio.AccessKey = %q, want %q", cfg.Minio.AccessKey, "myaccesskey")
}
if cfg.Minio.SecretKey != "mysecretkey" {
t.Errorf("Minio.SecretKey = %q, want %q", cfg.Minio.SecretKey, "mysecretkey")
}
if cfg.Minio.Bucket != "test-bucket" {
t.Errorf("Minio.Bucket = %q, want %q", cfg.Minio.Bucket, "test-bucket")
}
if cfg.Minio.UseSSL != true {
t.Errorf("Minio.UseSSL = %v, want %v", cfg.Minio.UseSSL, true)
}
if cfg.Minio.ChunkSize != 33554432 {
t.Errorf("Minio.ChunkSize = %d, want %d", cfg.Minio.ChunkSize, 33554432)
}
if cfg.Minio.MaxFileSize != 107374182400 {
t.Errorf("Minio.MaxFileSize = %d, want %d", cfg.Minio.MaxFileSize, 107374182400)
}
if cfg.Minio.MinChunkSize != 10485760 {
t.Errorf("Minio.MinChunkSize = %d, want %d", cfg.Minio.MinChunkSize, 10485760)
}
if cfg.Minio.SessionTTL != 24 {
t.Errorf("Minio.SessionTTL = %d, want %d", cfg.Minio.SessionTTL, 24)
}
}
func TestLoadWithoutMinioConfig(t *testing.T) {
content := []byte(`server_port: "8080"
slurm_api_url: "http://localhost:6820"
slurm_user_name: "root"
slurm_jwt_key_path: "/etc/slurm/jwt_hs256.key"
mysql_dsn: "root:@tcp(127.0.0.1:3306)/hpc_platform?parseTime=true"
`)
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
if err := os.WriteFile(path, content, 0644); err != nil {
t.Fatalf("write temp config: %v", err)
}
cfg, err := Load(path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Minio.Endpoint != "" {
t.Errorf("Minio.Endpoint = %q, want empty string", cfg.Minio.Endpoint)
}
if cfg.Minio.AccessKey != "" {
t.Errorf("Minio.AccessKey = %q, want empty string", cfg.Minio.AccessKey)
}
if cfg.Minio.SecretKey != "" {
t.Errorf("Minio.SecretKey = %q, want empty string", cfg.Minio.SecretKey)
}
if cfg.Minio.Bucket != "" {
t.Errorf("Minio.Bucket = %q, want empty string", cfg.Minio.Bucket)
}
if cfg.Minio.UseSSL != false {
t.Errorf("Minio.UseSSL = %v, want false", cfg.Minio.UseSSL)
}
}
func TestLoadMinioDefaults(t *testing.T) {
content := []byte(`server_port: "8080"
slurm_api_url: "http://localhost:6820"
slurm_user_name: "root"
slurm_jwt_key_path: "/etc/slurm/jwt_hs256.key"
mysql_dsn: "root:@tcp(127.0.0.1:3306)/hpc_platform?parseTime=true"
minio:
endpoint: "localhost:9000"
access_key: "minioadmin"
secret_key: "minioadmin"
bucket: "uploads"
`)
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
if err := os.WriteFile(path, content, 0644); err != nil {
t.Fatalf("write temp config: %v", err)
}
cfg, err := Load(path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Minio.ChunkSize != 16<<20 {
t.Errorf("Minio.ChunkSize = %d, want %d", cfg.Minio.ChunkSize, 16<<20)
}
if cfg.Minio.MaxFileSize != 50<<30 {
t.Errorf("Minio.MaxFileSize = %d, want %d", cfg.Minio.MaxFileSize, 50<<30)
}
if cfg.Minio.MinChunkSize != 5<<20 {
t.Errorf("Minio.MinChunkSize = %d, want %d", cfg.Minio.MinChunkSize, 5<<20)
}
if cfg.Minio.SessionTTL != 48 {
t.Errorf("Minio.SessionTTL = %d, want %d", cfg.Minio.SessionTTL, 48)
}
}