2016-09-10 11:23:28 +02:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017, 2018 MinIO, Inc.
|
2016-09-10 11:23:28 +02: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 09:51:25 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-09-06 17:03:18 +02:00
|
|
|
"context"
|
2017-02-27 23:59:53 +01:00
|
|
|
"os"
|
2016-09-10 09:51:25 +02:00
|
|
|
"testing"
|
2019-10-23 07:59:13 +02:00
|
|
|
|
|
|
|
"github.com/minio/minio/cmd/config"
|
2016-09-10 09:51:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServerConfig(t *testing.T) {
|
2018-08-15 06:41:47 +02:00
|
|
|
objLayer, fsDir, err := prepareFS()
|
2016-09-10 09:51:25 +02:00
|
|
|
if err != nil {
|
2018-08-15 06:41:47 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(fsDir)
|
|
|
|
|
|
|
|
if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil {
|
2016-09-10 09:51:25 +02:00
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:59:13 +02:00
|
|
|
if globalServerRegion != globalMinioDefaultRegion {
|
|
|
|
t.Errorf("Expecting region `us-east-1` found %s", globalServerRegion)
|
2016-09-10 09:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set new region and verify.
|
2019-10-23 07:59:13 +02:00
|
|
|
config.SetRegion(globalServerConfig, "us-west-1")
|
|
|
|
region, err := config.LookupRegion(globalServerConfig[config.RegionSubSys][config.Default])
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-09-10 09:51:25 +02:00
|
|
|
}
|
2019-10-23 07:59:13 +02:00
|
|
|
if region != "us-west-1" {
|
|
|
|
t.Errorf("Expecting region `us-west-1` found %s", globalServerRegion)
|
2016-09-10 09:51:25 +02:00
|
|
|
}
|
|
|
|
|
2019-11-21 13:24:51 +01:00
|
|
|
if err := saveServerConfig(context.Background(), objLayer, globalServerConfig); err != nil {
|
2016-09-10 09:51:25 +02:00
|
|
|
t.Fatalf("Unable to save updated config file %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize server config.
|
2020-12-01 20:59:03 +01:00
|
|
|
if err := loadConfig(objLayer); err != nil {
|
2016-09-10 09:51:25 +02:00
|
|
|
t.Fatalf("Unable to initialize from updated config file %s", err)
|
|
|
|
}
|
|
|
|
}
|