storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/config-current_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2016, 2017, 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "context" 21 "os" 22 "testing" 23 24 "storj.io/minio/cmd/config" 25 ) 26 27 func TestServerConfig(t *testing.T) { 28 objLayer, fsDir, err := prepareFS() 29 if err != nil { 30 t.Fatal(err) 31 } 32 defer os.RemoveAll(fsDir) 33 34 if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil { 35 t.Fatalf("Init Test config failed") 36 } 37 38 if globalServerRegion != globalMinioDefaultRegion { 39 t.Errorf("Expecting region `us-east-1` found %s", globalServerRegion) 40 } 41 42 // Set new region and verify. 43 config.SetRegion(globalServerConfig, "us-west-1") 44 region, err := config.LookupRegion(globalServerConfig[config.RegionSubSys][config.Default]) 45 if err != nil { 46 t.Fatal(err) 47 } 48 if region != "us-west-1" { 49 t.Errorf("Expecting region `us-west-1` found %s", globalServerRegion) 50 } 51 52 if err := saveServerConfig(context.Background(), objLayer, globalServerConfig); err != nil { 53 t.Fatalf("Unable to save updated config file %s", err) 54 } 55 56 // Initialize server config. 57 if err := loadConfig(objLayer); err != nil { 58 t.Fatalf("Unable to initialize from updated config file %s", err) 59 } 60 }