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