Simplify running cmd.Main() for external tests (#3636)

An external test that runs cmd.Main() has a difficulty to set cmd arguments
and MINIO_{ACCESS,SECRET}_KEY values, this commit changes a little the current
behavior in a way that helps external tests.
master
Anis Elleuch 8 years ago committed by Harshavardhana
parent cccf77229d
commit 8e49a3d047
  1. 8
      cmd/globals.go
  2. 8
      cmd/main.go
  3. 8
      main.go

@ -110,11 +110,11 @@ var (
// Minio server user agent string. // Minio server user agent string.
globalServerUserAgent = "Minio/" + ReleaseTag + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")" globalServerUserAgent = "Minio/" + ReleaseTag + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")"
// Access key passed from the environment // Global server's access key
globalEnvAccessKey = os.Getenv("MINIO_ACCESS_KEY") globalEnvAccessKey = ""
// Secret key passed from the environment // Global server's secret key
globalEnvSecretKey = os.Getenv("MINIO_SECRET_KEY") globalEnvSecretKey = ""
// url.URL endpoints of disks that belong to the object storage. // url.URL endpoints of disks that belong to the object storage.
globalEndpoints = []*url.URL{} globalEndpoints = []*url.URL{}

@ -190,6 +190,8 @@ func minioInit(ctx *cli.Context) {
enableLoggers() enableLoggers()
// Fetch access keys from environment variables and update the config. // Fetch access keys from environment variables and update the config.
globalEnvAccessKey = os.Getenv("MINIO_ACCESS_KEY")
globalEnvSecretKey = os.Getenv("MINIO_SECRET_KEY")
if globalEnvAccessKey != "" && globalEnvSecretKey != "" { if globalEnvAccessKey != "" && globalEnvSecretKey != "" {
// Set new credentials. // Set new credentials.
serverConfig.SetCredential(credential{ serverConfig.SetCredential(credential{
@ -210,7 +212,7 @@ func minioInit(ctx *cli.Context) {
} }
// Main main for minio server. // Main main for minio server.
func Main() { func Main(args []string, exitFn func(int)) {
app := registerApp() app := registerApp()
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {
// Valid input arguments to main. // Valid input arguments to main.
@ -224,5 +226,7 @@ func Main() {
} }
// Run the app - exit on error. // Run the app - exit on error.
app.RunAndExitOnError() if err := app.Run(args); err != nil {
exitFn(1)
}
} }

@ -22,8 +22,12 @@
package main // import "github.com/minio/minio" package main // import "github.com/minio/minio"
import minio "github.com/minio/minio/cmd" import (
"os"
minio "github.com/minio/minio/cmd"
)
func main() { func main() {
minio.Main() minio.Main(os.Args, os.Exit)
} }

Loading…
Cancel
Save