MinIO's testing infrastructure provides comprehensive coverage through unit tests, integration tests, and race detection. The test suite validates object storage functionality across multiple backend implementations (filesystem and erasure-coded) to ensure consistent behavior in different deployment modes.
Key Components:
cmd/*_test.go validating individual componentsdocs/*/ testing end-to-end scenariostest-utils_test.go for test setup and executionThe Makefile at the repository root provides targets for running different test suites. For information about building MinIO from source, see Building from Source. For details on code organization, see Code Organization.
Sources: Makefile48-96 cmd/test-utils_test.go72-125
MinIO's test suite is organized around the cmd package, with test files following Go's standard *_test.go naming convention. Tests are structured to validate the ObjectLayer interface implementation across different backend types.
cmd/
├── object-api-multipart_test.go # Multipart upload tests
├── object-api-putobject_test.go # PutObject operation tests
├── object-api-utils_test.go # Utility function tests
├── object_api_suite_test.go # Comprehensive API suite
├── encryption-v1_test.go # Encryption functionality tests
├── generic-handlers_test.go # Middleware handler tests
└── test-utils_test.go # Test utilities (referenced)
| Category | Purpose | Example File |
|---|---|---|
| Object Operations | Tests for core object operations (Put, Get, Delete) | object-api-putobject_test.go |
| Multipart Uploads | Tests for multipart upload lifecycle | object-api-multipart_test.go |
| Encryption | Tests for SSE-C, SSE-S3, SSE-KMS encryption | encryption-v1_test.go |
| Middleware | Tests for request handling middleware | generic-handlers_test.go |
| Utilities | Tests for helper functions | object-api-utils_test.go |
| Integration | End-to-end API tests | object_api_suite_test.go |
Sources: cmd/object-api-multipart_test.go1-42 cmd/object-api-putobject_test.go1-29 cmd/object_api_suite_test.go1-28
MinIO employs a custom test execution framework that enables tests to run against multiple storage backend implementations. This ensures that the ObjectLayer interface behaves consistently across filesystem and erasure-coded backends.
Test Execution Pattern
The framework uses a two-tier structure:
Sources: cmd/object-api-multipart_test.go36-42
The framework supports two execution modes based on test complexity:
| Function | Purpose | Use Case |
|---|---|---|
ExecObjectLayerTest | Standard test execution | Most functional tests |
ExecExtendedObjectLayerTest | Extended test execution with additional setup | Tests requiring complex initialization |
Sources: cmd/object-api-multipart_test.go36-42 cmd/object_api_suite_test.go20-28
MinIO tests run against multiple storage backends to ensure consistent behavior across deployment configurations. The test framework automatically provisions and tears down backend instances.
| Backend Type | Description | Setup Function | Disks |
|---|---|---|---|
| Filesystem (FS) | Single-disk filesystem backend | prepareFS() | 1 |
| Erasure | Multi-disk erasure-coded backend | prepareErasure() | 16 (default) |
Tests receive an instanceType parameter indicating which backend is being tested:
This allows tests to adjust expectations or skip operations not supported by a particular backend.
Sources: cmd/object-api-multipart_test.go36-42
MinIO provides extensive test utilities in cmd/test-utils_test.go for common operations like server setup, bucket creation, object uploads, and test data generation.
The TestServer struct encapsulates a complete MinIO instance for testing:
Key fields in TestServer:
Root - Temporary directory for test dataDisks - Configured endpoints for the storage backendAccessKey/SecretKey - Test credentials (defaults from auth.DefaultAccessKey)Server - HTTP test server instanceObj - ObjectLayer interface implementationcancel - Context cancellation function for cleanupSources: cmd/test-utils_test.go314-323
Usage pattern:
Sources: cmd/test-utils_test.go328-458
MinIO provides specialized functions for setting up different storage backends:
| Function | Purpose | Disks | Return Type |
|---|---|---|---|
prepareFS(ctx) | Setup filesystem backend | 1 | (ObjectLayer, string, error) |
prepareErasure(ctx, nDisks) | Setup erasure backend (configurable) | nDisks | (ObjectLayer, []string, error) |
prepareErasure16(ctx) | Setup 16-disk erasure backend | 16 | (ObjectLayer, []string, error) |
prepareErasureSets32(ctx) | Setup 32-disk erasure backend | 32 | (ObjectLayer, []string, error) |
Example usage:
Sources: cmd/test-utils_test.go190-245
Random string generation:
letterBytes = "abcdefghijklmnopqrstuvwxyz01234569"randmu mutexSources: cmd/test-utils_test.go266-302
Test utilities provide functions for generating AWS Signature V4 signatures:
| Function | Purpose |
|---|---|
signRequest | Sign HTTP request with V4 signature |
signStreamingRequest | Sign streaming upload request |
getCredential | Generate credential string |
getScope | Generate signature scope |
getSigningKey | Derive signing key |
getSignature | Calculate signature |
Sources: cmd/test-utils_test.go1-70 (inferred from standard AWS signature utilities)
Sources: cmd/test-utils_test.go1-70 (inferred from common patterns)
Test utilities include helpers for constructing HTTP requests:
newTestRequest - Create HTTP request with proper headersnewTestSignedRequest - Create signed requestnewTestStreamingRequest - Create streaming upload requestexecRequest - Execute request and return responseSources: cmd/test-utils_test.go328-458
Tests use the TestErrHandler interface to make test utilities compatible with Go's testing framework:
This allows test utilities to work with:
*testing.T - Standard unit tests*testing.B - Benchmark testsSources: cmd/test-utils_test.go247-253
The TestMain function performs global test environment initialization:
Key initialization steps:
globalIsTesting = trueSources: cmd/test-utils_test.go72-125
Multipart upload tests validate the complete lifecycle of multipart uploads, including initiation, part uploads, completion, and abortion.
| Test Function | Purpose | Key Validations |
|---|---|---|
testObjectNewMultipartUpload | Upload initiation | UploadID generation, metadata creation |
testObjectAbortMultipartUpload | Upload abortion | Cleanup of parts and metadata |
testObjectCompleteMultipartUpload | Upload completion | Part assembly, ETag calculation |
testObjectListMultipartUploads | List in-progress uploads | Pagination, filtering |
testListObjectParts | List uploaded parts | Part ordering, metadata |
Sources: cmd/object-api-multipart_test.go36-42
PutObject tests validate the core object upload functionality, including various size classes, checksums, and error conditions.
Tests cover various object sizes and configurations:
Sources: cmd/object-api-putobject_test.go1-29
Encryption tests validate all three encryption modes supported by MinIO: SSE-C (customer-provided keys), SSE-S3 (MinIO-managed keys), and SSE-KMS (KMS-managed keys).
| Encryption Mode | Test Functions | Key Aspects |
|---|---|---|
| SSE-C | Customer key tests | Key matching, tamper detection |
| SSE-S3 | Managed encryption tests | Automatic key generation, ETag handling |
| SSE-KMS | KMS integration tests | Key ID validation, context passing |
Sources: cmd/encryption-v1_test.go1-27
Handler tests validate the HTTP request processing pipeline, including middleware components for authentication, validation, and error handling.
Tests validate middleware behavior for:
.minio.sysSources: cmd/generic-handlers_test.go1-27
Utility tests validate helper functions used throughout the codebase, including path handling, metadata extraction, and data encoding.
| Utility Category | Functions Tested | Purpose |
|---|---|---|
| Path Handling | pathJoin, retainSlash | Correct slash handling, path joining |
| Bucket Names | IsValidBucketName | DNS-compliant validation |
| Object Names | IsValidObjectName, IsValidObjectPrefix | Character and length validation |
| Metadata | extractMetadata, extractMetadataFromReq | Header parsing, user metadata extraction |
| Hash Functions | getMD5Hash, getSHA256Hash | Checksum calculation |
Sources: cmd/object-api-utils_test.go1-39
MinIO's test infrastructure is organized into three primary categories, each serving a distinct purpose in validating system behavior.
Sources: Makefile48-96
Unit tests validate individual components and are written as Go test files following the *_test.go naming convention.
Execution via Makefile:
Key characteristics:
cmd/*_test.go fileskqueue (for BSD queue support) and dev (development mode)Sources: Makefile48-51 cmd/test-utils_test.go72-125
Integration tests validate end-to-end scenarios and multi-component interactions through shell scripts.
Available Integration Test Targets:
| Makefile Target | Purpose | Script Location |
|---|---|---|
test-iam | IAM functionality with external IDP and etcd | Direct Go test execution |
test-iam-ldap-upgrade-import | LDAP IAM import and upgrade | buildscripts/minio-iam-ldap-upgrade-import-test.sh |
test-replication | Multi-site replication (2-site, 3-site) | docs/bucket/replication/*.sh |
test-site-replication-* | Site replication with LDAP/OIDC/MinIO IDP | docs/site-replication/*.sh |
test-ilm | ILM expiry and replication | docs/bucket/replication/setup_ilm_expiry_replication.sh |
test-ilm-transition | ILM tiering with healing | docs/bucket/lifecycle/setup_ilm_transition.sh |
test-decom | Pool decommissioning scenarios | docs/distributed/decom*.sh |
test-versioning | Bucket versioning | docs/bucket/versioning/versioning-tests.sh |
Example execution:
Sources: Makefile57-125
Race detection tests use Go's race detector to identify data races in concurrent code execution.
Execution:
Race detector configuration:
GORACE=history_size=7CGO_ENABLED=1 (required for race detector)IAM-specific race testing:
Sources: Makefile88-96
The Makefile provides convenient targets for different test scenarios:
Sources: Makefile48-138
For more granular control, use Go's test command directly:
Sources: Makefile50-51 cmd/test-utils_test.go72-125
Sources: Makefile48-51
MinIO tests use various approaches for managing test data, including in-memory buffers, temporary files, and random data generation.
| Pattern | Use Case | Implementation |
|---|---|---|
| Repeated bytes | Simple fixed-size data | bytes.Repeat([]byte("a"), size) |
| Random data | Realistic object content | rand.Reader |
| Specific patterns | Boundary testing | Custom byte sequences |
| Pre-computed hashes | Hash validation | MD5/SHA256 of known data |
Tests follow Go's cleanup pattern:
defer statements - Ensure cleanup runs even on test failureSources: cmd/object-api-multipart_test.go1-35 cmd/object-api-putobject_test.go1-29
MinIO tests are designed to run in isolation, with each test receiving a fresh ObjectLayer instance.
context.ContextMost MinIO tests can run in parallel:
Sources: cmd/object_api_suite_test.go1-28
Tests extensively validate error conditions to ensure proper error handling throughout the codebase.
| Error Category | Test Approach | Example Validations |
|---|---|---|
| Invalid inputs | Direct error checking | ErrInvalidBucketName, ErrInvalidObjectName |
| Not found errors | Existence validation | ErrNoSuchBucket, ErrNoSuchKey |
| Permission errors | Auth/ACL testing | ErrAccessDenied |
| Resource errors | Limit testing | ErrStorageFull, ErrTooManyRequests |
| Concurrency errors | Race condition testing | Upload ID conflicts, version conflicts |
Tests validate both error presence and error type:
Sources: cmd/object-api-errors.go1-26 cmd/api-errors.go1-52
MinIO's test infrastructure is designed to integrate seamlessly with continuous integration systems.
Some tests skip on certain platforms:
Refresh this wiki