Skip to content

Commit fabca4d

Browse files
committed
feat: add S3 region support for MinIO and update related tests
1 parent 3c91c07 commit fabca4d

3 files changed

Lines changed: 86 additions & 8 deletions

File tree

integration/bundle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type BundleConfig struct {
3232
RedisURI string
3333
S3Bucket string
3434
S3Endpoint string
35+
S3Region string
3536
S3AccessKey string
3637
S3SecretKey string
3738
}
@@ -81,6 +82,9 @@ func StartBundle(ctx context.Context, cfg BundleConfig) (*BundleProcess, error)
8182
"--initial-s3-endpoint", cfg.S3Endpoint,
8283
"--initial-s3-force-path-style",
8384
)
85+
if cfg.S3Region != "" {
86+
args = append(args, "--initial-s3-region", cfg.S3Region)
87+
}
8488
}
8589

8690
cmd := exec.CommandContext(ctx, binaryPath, args...)

integration/containers.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ type MinIOContainer struct {
8484
Endpoint string
8585
AccessKey string
8686
SecretKey string
87+
Region string
8788
network *testcontainers.DockerNetwork
8889
}
8990

90-
// StartMinIO starts MinIO for S3 testing.
91+
// StartMinIO starts MinIO for S3 testing with default region (us-east-1).
9192
// Uses HTTP health endpoint for readiness check.
9293
func StartMinIO(ctx context.Context) (*MinIOContainer, error) {
94+
return StartMinIOWithRegion(ctx, "")
95+
}
96+
97+
// StartMinIOWithRegion starts MinIO with a custom region for S3 testing.
98+
// If region is empty, MinIO uses its default (us-east-1).
99+
func StartMinIOWithRegion(ctx context.Context, region string) (*MinIOContainer, error) {
93100
accessKey := "minioadmin"
94101
secretKey := "minioadmin"
95102

@@ -100,17 +107,22 @@ func StartMinIO(ctx context.Context) (*MinIOContainer, error) {
100107
}
101108
networkName := dockerNet.Name
102109

110+
env := map[string]string{
111+
"MINIO_ROOT_USER": accessKey,
112+
"MINIO_ROOT_PASSWORD": secretKey,
113+
}
114+
if region != "" {
115+
env["MINIO_REGION"] = region
116+
}
117+
103118
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
104119
ContainerRequest: testcontainers.ContainerRequest{
105120
Image: minioImage,
106121
ExposedPorts: []string{"9000/tcp"},
107-
Env: map[string]string{
108-
"MINIO_ROOT_USER": accessKey,
109-
"MINIO_ROOT_PASSWORD": secretKey,
110-
},
111-
Cmd: []string{"server", "/data"},
112-
WaitingFor: wait.ForHTTP("/minio/health/live").WithPort("9000/tcp"),
113-
Networks: []string{networkName},
122+
Env: env,
123+
Cmd: []string{"server", "/data"},
124+
WaitingFor: wait.ForHTTP("/minio/health/live").WithPort("9000/tcp"),
125+
Networks: []string{networkName},
114126
NetworkAliases: map[string][]string{
115127
networkName: {"minio"},
116128
},
@@ -158,6 +170,7 @@ func StartMinIO(ctx context.Context) (*MinIOContainer, error) {
158170
Endpoint: externalEndpoint,
159171
AccessKey: accessKey,
160172
SecretKey: secretKey,
173+
Region: region,
161174
network: dockerNet,
162175
}, nil
163176
}

integration/integration_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,64 @@ func TestBundleWithS3Storage(t *testing.T) {
106106
require.NoError(t, err, "Bundle should shutdown cleanly")
107107
t.Log("Bundle shutdown complete")
108108
}
109+
110+
// TestBundleWithS3CustomRegion verifies that the bundle works with MinIO
111+
// configured with a custom region. This tests the fix for GitHub issue #47.
112+
func TestBundleWithS3CustomRegion(t *testing.T) {
113+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
114+
defer cancel()
115+
116+
customRegion := "custom-test-region"
117+
118+
// Start MongoDB
119+
mongo, err := StartMongo(ctx)
120+
require.NoError(t, err, "Failed to start MongoDB")
121+
defer mongo.Terminate(ctx)
122+
t.Logf("MongoDB URI: %s", mongo.URI)
123+
124+
// Start Redis
125+
redis, err := StartRedis(ctx)
126+
require.NoError(t, err, "Failed to start Redis")
127+
defer redis.Terminate(ctx)
128+
t.Logf("Redis URI: %s", redis.URI)
129+
130+
// Start MinIO with custom region
131+
minio, err := StartMinIOWithRegion(ctx, customRegion)
132+
require.NoError(t, err, "Failed to start MinIO with custom region")
133+
defer minio.Terminate(ctx)
134+
t.Logf("MinIO Endpoint: %s, Region: %s", minio.Endpoint, minio.Region)
135+
136+
// Start bundle with S3 and matching region
137+
bundle, err := StartBundle(ctx, BundleConfig{
138+
MongoURI: mongo.URI,
139+
RedisURI: redis.URI,
140+
S3Bucket: "anytype-data",
141+
S3Endpoint: minio.Endpoint,
142+
S3Region: customRegion,
143+
S3AccessKey: minio.AccessKey,
144+
S3SecretKey: minio.SecretKey,
145+
})
146+
require.NoError(t, err, "Failed to start bundle")
147+
defer bundle.Cleanup()
148+
defer bundle.Stop()
149+
150+
// Wait for ready
151+
err = bundle.WaitReady(90 * time.Second)
152+
require.NoError(t, err, "Bundle should become ready with custom S3 region")
153+
t.Log("Bundle is ready")
154+
155+
// Verify S3 backend selected
156+
err = bundle.WaitForS3Backend(5 * time.Second)
157+
require.NoError(t, err, "S3 storage backend should be selected")
158+
t.Log("S3 storage backend confirmed")
159+
160+
// Verify TCP port
161+
err = bundle.VerifyPort("33010")
162+
require.NoError(t, err, "Port 33010 should be listening")
163+
t.Log("Port 33010 is listening")
164+
165+
// Graceful shutdown
166+
err = bundle.Stop()
167+
require.NoError(t, err, "Bundle should shutdown cleanly")
168+
t.Log("Bundle shutdown complete")
169+
}

0 commit comments

Comments
 (0)