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