Files
mtusi2026lab4/internal/adapter/objectstore/minio_test.go
T

38 lines
1.8 KiB
Go

package objectstore
import (
"testing"
"time"
)
func TestNewMinIOStoreValidatesConfiguration(t *testing.T) {
testCases := []struct {
name string
endpoint string
bucket string
accessKey string
secretKey string
timeout time.Duration
wantError bool
}{
{name: "valid HTTP", endpoint: "http://minio:9000", bucket: "attachments", accessKey: "api", secretKey: "secret", timeout: time.Second},
{name: "valid HTTPS", endpoint: "https://s3.example.test", bucket: "attachments", accessKey: "api", secretKey: "secret", timeout: time.Second},
{name: "relative endpoint", endpoint: "minio:9000", bucket: "attachments", accessKey: "api", secretKey: "secret", timeout: time.Second, wantError: true},
{name: "endpoint path", endpoint: "http://minio:9000/path", bucket: "attachments", accessKey: "api", secretKey: "secret", timeout: time.Second, wantError: true},
{name: "embedded credentials", endpoint: "http://user:pass@minio:9000", bucket: "attachments", accessKey: "api", secretKey: "secret", timeout: time.Second, wantError: true},
{name: "empty bucket", endpoint: "http://minio:9000", accessKey: "api", secretKey: "secret", timeout: time.Second, wantError: true},
{name: "empty credentials", endpoint: "http://minio:9000", bucket: "attachments", timeout: time.Second, wantError: true},
{name: "invalid timeout", endpoint: "http://minio:9000", bucket: "attachments", accessKey: "api", secretKey: "secret", wantError: true},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
_, err := NewMinIOStore(testCase.endpoint, "us-east-1", testCase.bucket,
testCase.accessKey, testCase.secretKey, testCase.timeout)
if (err != nil) != testCase.wantError {
t.Fatalf("NewMinIOStore() error = %v, wantError %v", err, testCase.wantError)
}
})
}
}