2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-09-10 05:23:28 -04:00
|
|
|
|
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
|
|
|
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/config"
|
2016-09-10 03:51:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServerConfig(t *testing.T) {
|
2022-07-21 14:52:18 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
objLayer, fsDir, err := prepareFS(ctx)
|
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")
|
|
|
|
}
|
|
|
|
|
2021-11-25 16:06:25 -05:00
|
|
|
if globalSite.Region != globalMinioDefaultRegion {
|
|
|
|
t.Errorf("Expecting region `us-east-1` found %s", globalSite.Region)
|
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")
|
2021-11-25 16:06:25 -05:00
|
|
|
site, err := config.LookupSite(
|
|
|
|
globalServerConfig[config.SiteSubSys][config.Default],
|
|
|
|
globalServerConfig[config.RegionSubSys][config.Default],
|
|
|
|
)
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-09-10 03:51:25 -04:00
|
|
|
}
|
2021-11-25 16:06:25 -05:00
|
|
|
if site.Region != "us-west-1" {
|
|
|
|
t.Errorf("Expecting region `us-west-1` found %s", globalSite.Region)
|
2016-09-10 03:51:25 -04:00
|
|
|
}
|
|
|
|
|
2019-11-21 07:24:51 -05:00
|
|
|
if err := saveServerConfig(context.Background(), objLayer, globalServerConfig); err != nil {
|
2016-09-10 03:51:25 -04:00
|
|
|
t.Fatalf("Unable to save updated config file %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize server config.
|
2020-12-01 14:59:03 -05: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)
|
|
|
|
}
|
|
|
|
}
|