2016-09-10 05:23:28 -04:00
|
|
|
/*
|
2017-01-18 15:24:34 -05:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-09-10 05:23:28 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-09-10 03:51:25 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2017-02-27 17:59:53 -05:00
|
|
|
"os"
|
2016-09-10 03:51:25 -04:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServerConfig(t *testing.T) {
|
2017-01-18 15:24:34 -05:00
|
|
|
rootPath, err := newTestConfig(globalMinioDefaultRegion)
|
2016-09-10 03:51:25 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
2016-11-10 02:37:12 -05:00
|
|
|
// remove the root directory after the test ends.
|
2016-09-10 03:51:25 -04:00
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
2017-01-18 15:24:34 -05:00
|
|
|
if serverConfig.GetRegion() != globalMinioDefaultRegion {
|
2016-09-10 03:51:25 -04:00
|
|
|
t.Errorf("Expecting region `us-east-1` found %s", serverConfig.GetRegion())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new region and verify.
|
|
|
|
serverConfig.SetRegion("us-west-1")
|
|
|
|
if serverConfig.GetRegion() != "us-west-1" {
|
|
|
|
t.Errorf("Expecting region `us-west-1` found %s", serverConfig.GetRegion())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new amqp notification id.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Notify.SetAMQPByID("2", amqpNotify{})
|
|
|
|
savedNotifyCfg1 := serverConfig.Notify.GetAMQPByID("2")
|
2016-09-10 03:51:25 -04:00
|
|
|
if !reflect.DeepEqual(savedNotifyCfg1, amqpNotify{}) {
|
|
|
|
t.Errorf("Expecting AMQP config %#v found %#v", amqpNotify{}, savedNotifyCfg1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new elastic search notification id.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Notify.SetElasticSearchByID("2", elasticSearchNotify{})
|
|
|
|
savedNotifyCfg2 := serverConfig.Notify.GetElasticSearchByID("2")
|
2016-09-10 03:51:25 -04:00
|
|
|
if !reflect.DeepEqual(savedNotifyCfg2, elasticSearchNotify{}) {
|
|
|
|
t.Errorf("Expecting Elasticsearch config %#v found %#v", elasticSearchNotify{}, savedNotifyCfg2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new redis notification id.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Notify.SetRedisByID("2", redisNotify{})
|
|
|
|
savedNotifyCfg3 := serverConfig.Notify.GetRedisByID("2")
|
2016-09-10 03:51:25 -04:00
|
|
|
if !reflect.DeepEqual(savedNotifyCfg3, redisNotify{}) {
|
|
|
|
t.Errorf("Expecting Redis config %#v found %#v", redisNotify{}, savedNotifyCfg3)
|
|
|
|
}
|
|
|
|
|
2016-12-15 11:23:48 -05:00
|
|
|
// Set new kafka notification id.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Notify.SetKafkaByID("2", kafkaNotify{})
|
|
|
|
savedNotifyCfg4 := serverConfig.Notify.GetKafkaByID("2")
|
2016-12-15 11:23:48 -05:00
|
|
|
if !reflect.DeepEqual(savedNotifyCfg4, kafkaNotify{}) {
|
|
|
|
t.Errorf("Expecting Kafka config %#v found %#v", kafkaNotify{}, savedNotifyCfg4)
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:22:10 -05:00
|
|
|
// Set new Webhook notification id.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Notify.SetWebhookByID("2", webhookNotify{})
|
|
|
|
savedNotifyCfg5 := serverConfig.Notify.GetWebhookByID("2")
|
2017-01-09 17:22:10 -05:00
|
|
|
if !reflect.DeepEqual(savedNotifyCfg5, webhookNotify{}) {
|
|
|
|
t.Errorf("Expecting Webhook config %#v found %#v", webhookNotify{}, savedNotifyCfg3)
|
|
|
|
}
|
|
|
|
|
2016-09-10 03:51:25 -04:00
|
|
|
// Set new console logger.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Logger.SetConsole(consoleLogger{
|
2016-09-10 03:51:25 -04:00
|
|
|
Enable: true,
|
|
|
|
})
|
2017-02-09 18:20:54 -05:00
|
|
|
consoleCfg := serverConfig.Logger.GetConsole()
|
2016-09-10 03:51:25 -04:00
|
|
|
if !reflect.DeepEqual(consoleCfg, consoleLogger{Enable: true}) {
|
|
|
|
t.Errorf("Expecting console logger config %#v found %#v", consoleLogger{Enable: true}, consoleCfg)
|
|
|
|
}
|
2017-02-10 02:26:44 -05:00
|
|
|
// Set new console logger.
|
|
|
|
serverConfig.Logger.SetConsole(consoleLogger{
|
|
|
|
Enable: false,
|
|
|
|
})
|
2016-09-10 03:51:25 -04:00
|
|
|
|
|
|
|
// Set new file logger.
|
2017-02-09 18:20:54 -05:00
|
|
|
serverConfig.Logger.SetFile(fileLogger{
|
2016-09-10 03:51:25 -04:00
|
|
|
Enable: true,
|
|
|
|
})
|
2017-02-09 18:20:54 -05:00
|
|
|
fileCfg := serverConfig.Logger.GetFile()
|
2016-09-10 03:51:25 -04:00
|
|
|
if !reflect.DeepEqual(fileCfg, fileLogger{Enable: true}) {
|
|
|
|
t.Errorf("Expecting file logger config %#v found %#v", fileLogger{Enable: true}, consoleCfg)
|
|
|
|
}
|
2017-02-10 02:26:44 -05:00
|
|
|
// Set new file logger.
|
|
|
|
serverConfig.Logger.SetFile(fileLogger{
|
|
|
|
Enable: false,
|
|
|
|
})
|
2016-09-10 03:51:25 -04:00
|
|
|
|
|
|
|
// Match version.
|
2017-03-01 12:17:04 -05:00
|
|
|
if serverConfig.GetVersion() != v14 {
|
|
|
|
t.Errorf("Expecting version %s found %s", serverConfig.GetVersion(), v14)
|
2016-09-10 03:51:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to save.
|
|
|
|
if err := serverConfig.Save(); err != nil {
|
|
|
|
t.Fatalf("Unable to save updated config file %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do this only once here.
|
2017-03-02 17:21:30 -05:00
|
|
|
setConfigDir(rootPath)
|
2016-09-10 03:51:25 -04:00
|
|
|
|
|
|
|
// Initialize server config.
|
2017-02-27 17:59:53 -05:00
|
|
|
if err := loadConfig(envParams{}); err != nil {
|
2016-09-10 03:51:25 -04:00
|
|
|
t.Fatalf("Unable to initialize from updated config file %s", err)
|
|
|
|
}
|
|
|
|
}
|
2017-02-27 17:59:53 -05:00
|
|
|
|
|
|
|
func TestServerConfigWithEnvs(t *testing.T) {
|
|
|
|
|
|
|
|
os.Setenv("MINIO_BROWSER", "off")
|
|
|
|
defer os.Unsetenv("MINIO_BROWSER")
|
|
|
|
|
|
|
|
os.Setenv("MINIO_ACCESS_KEY", "minio")
|
|
|
|
defer os.Unsetenv("MINIO_ACCESS_KEY")
|
|
|
|
|
|
|
|
os.Setenv("MINIO_SECRET_KEY", "minio123")
|
|
|
|
defer os.Unsetenv("MINIO_SECRET_KEY")
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
globalIsEnvBrowser = false
|
|
|
|
globalIsEnvCreds = false
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Get test root.
|
|
|
|
rootPath, err := getTestRoot()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do this only once here.
|
2017-03-02 17:21:30 -05:00
|
|
|
setConfigDir(rootPath)
|
2017-02-27 17:59:53 -05:00
|
|
|
|
|
|
|
// Init config
|
|
|
|
initConfig()
|
|
|
|
|
|
|
|
// remove the root directory after the test ends.
|
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
|
|
|
// Check if serverConfig has
|
|
|
|
if serverConfig.GetBrowser() != "off" {
|
|
|
|
t.Errorf("Expecting browser `off` found %s", serverConfig.GetBrowser())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if serverConfig has
|
|
|
|
cred := serverConfig.GetCredential()
|
|
|
|
|
|
|
|
if cred.AccessKey != "minio" {
|
|
|
|
t.Errorf("Expecting access key to be `minio` found %s", cred.AccessKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cred.SecretKey != "minio123" {
|
|
|
|
t.Errorf("Expecting access key to be `minio123` found %s", cred.SecretKey)
|
|
|
|
}
|
|
|
|
}
|