You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Default credentials
Description: The CI job provisions a MinIO service with trivial static credentials (MINIO_ROOT_USER/MINIO_ROOT_PASSWORD and propagated MINIO_ACCESS_KEY/MINIO_SECRET_KEY all set to minioadmin), which can be abused if the service becomes reachable from other containers/jobs or if this pattern is copied to non-test environments. config.yml [11-22]
Description: Test code defaults to MINIO_ACCESS_KEY/MINIO_SECRET_KEY of minioadmin and forces Secure: false (HTTP), which can lead to credentials and data being sent unencrypted if the endpoint is not strictly local/isolated or if these defaults are reused outside CI. client_test.go [19-24]
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Ignored errors: The test setup and file writer operations ignore potential errors (e.g., os.Getwd(), os.MkdirAll(), w.WriteLine(), and w.Close()), reducing failure visibility and making debugging harder.
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Hardcoded credentials: The PR introduces default MinIO credentials (minioadmin/minioadmin) in test configuration and environment fallbacks, which may constitute committed secrets unless strictly scoped to ephemeral local/CI-only containers.
The new file/minio/glob_test.go is in a different package (minio_test) than its setup code in file/minio/client_test.go (minio), causing tests to fail. Move them to the same package to share the TestMain setup function.
funcTestMain(m*testing.M) {
varerrerrorlog.SetFlags(log.Llongfile)
// test clienttestClient, err=newTestClient()
iferr!=nil {
fmt.Println("\033[34mSKIP: Minio server not available - run 'docker run -p 9000:9000 minio/minio server /data' for local testing\033[0m")
return
}
... (clipped34lines)
Solution Walkthrough:
Before:
// file/minio/client_test.gopackage minio
funcTestMain(m*testing.M) {
// ... client setup ...// Creates files needed for glob testsglobFiles:= []string{ "mc://.../glob/file-1.txt", ... }
for_, pth:=rangeglobFiles {
createTestFile(pth)
}
m.Run()
// ... cleanup ...
}
// file/minio/glob_test.gopackage minio_test // Different packagefuncTestGlob(t*testing.T) {
// This test will fail because the files it expects// are created in the 'minio' package's TestMain,// which does not run for the 'minio_test' package....
}
After:
// file/minio/client_test.gopackage minio
funcTestMain(m*testing.M) {
// ... client setup ...// Creates files needed for glob testsglobFiles:= []string{ "mc://.../glob/file-1.txt", ... }
for_, pth:=rangeglobFiles {
createTestFile(pth)
}
m.Run()
// ... cleanup ...
}
// file/minio/glob_test.gopackage minio // Same packagefuncTestGlob(t*testing.T) {
// This test will now pass because by being in the 'minio' package,// it shares the TestMain from client_test.go, ensuring// the required files are created before the test runs....
}
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a critical flaw where the new glob test will fail because its setup logic in client_test.go is in a different Go package and will not be executed.
High
Possible issue
Add endpoint to file.Options
In file/minio/glob_test.go, update file.Options to include the Host endpoint and set Secure: false to enable connection to the local MinIO test server.
Why: This suggestion correctly identifies that the Host and Secure fields are missing from file.Options, which would cause the test to fail. Applying this change is critical for the test's correctness.
High
Expose and wait for MinIO
In the CircleCI configuration, expose the MinIO container's port for clarity and consider adding a health-check step to ensure the service is ready before tests run.
Why: The suggestion correctly points out that exposing the MinIO port is good practice for clarity, although not strictly necessary for service-to-service communication within the same Docker network.
Medium
General
Properly skip tests in TestMain
In TestMain, replace return with os.Exit(0) when the Minio server is unavailable to ensure the test suite exits immediately with a success status.
if err != nil {
fmt.Println("\033[34mSKIP: Minio server not available - run 'docker run -p 9000:9000 minio/minio server /data' for local testing\033[0m")
- return+ os.Exit(0)
}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies that return from TestMain does not prevent other tests from running and proposes using os.Exit(0) for a clean skip, which is a valid improvement.
Medium
Avoid code duplication by centralizing helper
To avoid code duplication, move the getEnv function from file/minio/client_test.go and file/minio/glob_test.go into a single shared test utility file.
-func getEnv(key, fallback string) string {+// This function should be removed from this file and moved to a shared location.+// For example, create a new file `file/minio/test_helper.go` with:+/*+package minio++import "os"++func GetEnv(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}
+*/+// Then, in this file, you would call `minio.GetEnv(...)` after importing the `minio` package.
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that the getEnv function is duplicated in file/minio/client_test.go and file/minio/glob_test.go and proposes a valid refactoring to improve code maintainability.
Low
Learned best practice
Defer cleanup and check errors
Add defer cleanups immediately after successful bucket/object creation so early returns don't leak resources, and check/log errors from rmTestFile/rmBucket instead of ignoring them.
// make test bucket
if err := createBucket(testBucket); err != nil {
fmt.Printf("\033[34mSKIP: error creating bucket: %v\033[0m\n", err)
return
}
+defer func() {+ if err := rmBucket(testBucket); err != nil {+ log.Printf("cleanup: failed to remove bucket %q: %v", testBucket, err)+ }+}()
// create test files for reading
readFiles := []string{
fmt.Sprintf("mc://%v/read/test.txt", testBucket),
fmt.Sprintf("mc://%v/read/test.gz", testBucket),
}
for _, pth := range readFiles {
if err := createTestFile(pth); err != nil {
fmt.Printf("\033[34mSKIP: error creating %s: %v\033[0m\n", pth, err)
return
}
}
+defer func() {+ for _, pth := range readFiles {+ if err := rmTestFile(pth); err != nil {+ log.Printf("cleanup: failed to remove object %q: %v", pth, err)+ }+ }+}()
// create test files for glob testing
globFiles := []string{
fmt.Sprintf("mc://%v/glob/file-1.txt", testBucket),
fmt.Sprintf("mc://%v/glob/file2.txt", testBucket),
fmt.Sprintf("mc://%v/glob/file3.gz", testBucket),
fmt.Sprintf("mc://%v/glob/f1/file4.gz", testBucket),
fmt.Sprintf("mc://%v/glob/f3/file5.txt", testBucket),
fmt.Sprintf("mc://%v/glob/f5/file-6.txt", testBucket),
}
for _, pth := range globFiles {
if err := createTestFile(pth); err != nil {
fmt.Printf("\033[34mSKIP: error creating %s: %v\033[0m\n", pth, err)
return
}
}
+defer func() {+ for _, pth := range globFiles {+ if err := rmTestFile(pth); err != nil {+ log.Printf("cleanup: failed to remove object %q: %v", pth, err)+ }+ }+}()-// run-runRslt := m.Run()+os.Exit(m.Run())-// remove test objects-for _, pth := range readFiles {- rmTestFile(pth)-}-for _, pth := range globFiles {- rmTestFile(pth)-}--// remove test bucket-rmBucket(testBucket)--os.Exit(runRslt)-
Apply / Chat
Suggestion importance[1-10]: 6
__
Why:
Relevant best practice - For external API/resource interactions, only register cleanup after successful initialization, and ensure resources are cleaned up on all exit paths; also handle errors from cleanup calls instead of ignoring them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Tests, Enhancement
Description
Migrate MinIO tests from public server to local Docker instance
Remove MinIO tests from main file package, consolidate in dedicated module
Add CircleCI MinIO service container with environment configuration
Update test credentials to use environment variables with local defaults
Diagram Walkthrough
File Walkthrough
file_test.go
Remove MinIO tests from main file packagefile/file_test.go
TestGlob_Miniotest function and related helper functionsclient_test.go
Configure tests for local MinIO Docker instancefile/minio/client_test.go
lookups
play.minio.io:9000tolocalhost:9000Secureflag fromtruetofalsefor local HTTP instancefiles
glob_test.go
Add dedicated MinIO glob test modulefile/minio/glob_test.go
TestGlobwith environment variable configurationTestGlob_Miniopatternsconfig.yml
Add MinIO service container to CircleCI pipeline.circleci/config.yml
variables