| 
									
										
										
										
											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-10-06 03:48:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:22:15 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2022-10-14 18:08:40 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-08-13 10:25:43 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	"reflect" | 
					
						
							| 
									
										
										
										
											2016-10-13 11:22:15 +08:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | // Tests stripping standard ports from apiEndpoints.
 | 
					
						
							|  |  |  | func TestStripStandardPorts(t *testing.T) { | 
					
						
							|  |  |  | 	apiEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2:80", "https://127.0.0.3:443"} | 
					
						
							|  |  |  | 	expectedAPIEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2", "https://127.0.0.3"} | 
					
						
							| 
									
										
										
										
											2021-06-21 14:04:47 +08:00
										 |  |  | 	newAPIEndpoints := stripStandardPorts(apiEndpoints, "") | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if !reflect.DeepEqual(expectedAPIEndpoints, newAPIEndpoints) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected %#v, got %#v", expectedAPIEndpoints, newAPIEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apiEndpoints = []string{"http://%%%%%:9000"} | 
					
						
							| 
									
										
										
										
											2021-06-21 14:04:47 +08:00
										 |  |  | 	newAPIEndpoints = stripStandardPorts(apiEndpoints, "") | 
					
						
							| 
									
										
										
										
											2021-08-06 06:01:19 +08:00
										 |  |  | 	if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) { | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 		t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apiEndpoints = []string{"http://127.0.0.1:443", "https://127.0.0.1:80"} | 
					
						
							| 
									
										
										
										
											2021-06-21 14:04:47 +08:00
										 |  |  | 	newAPIEndpoints = stripStandardPorts(apiEndpoints, "") | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | // Test printing server common message.
 | 
					
						
							|  |  |  | func TestPrintServerCommonMessage(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2025-04-09 22:28:39 +08:00
										 |  |  | 	ctx, cancel := context.WithCancel(t.Context()) | 
					
						
							| 
									
										
										
										
											2022-10-14 18:08:40 +08:00
										 |  |  | 	defer cancel() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	obj, fsDir, err := prepareFS(ctx) | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							|  |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	apiEndpoints := []string{"http://127.0.0.1:9000"} | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	printServerCommonMsg(apiEndpoints) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Tests print cli access message.
 | 
					
						
							|  |  |  | func TestPrintCLIAccessMsg(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2025-04-09 22:28:39 +08:00
										 |  |  | 	ctx, cancel := context.WithCancel(t.Context()) | 
					
						
							| 
									
										
										
										
											2022-10-14 18:08:40 +08:00
										 |  |  | 	defer cancel() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	obj, fsDir, err := prepareFS(ctx) | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							|  |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	apiEndpoints := []string{"http://127.0.0.1:9000"} | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 	printCLIAccessMsg(apiEndpoints[0], "myminio") | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Test print startup message.
 | 
					
						
							|  |  |  | func TestPrintStartupMessage(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2025-04-09 22:28:39 +08:00
										 |  |  | 	ctx, cancel := context.WithCancel(t.Context()) | 
					
						
							| 
									
										
										
										
											2022-10-14 18:08:40 +08:00
										 |  |  | 	defer cancel() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	obj, fsDir, err := prepareFS(ctx) | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							|  |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	apiEndpoints := []string{"http://127.0.0.1:9000"} | 
					
						
							| 
									
										
										
										
											2020-10-10 00:59:52 +08:00
										 |  |  | 	printStartupMessage(apiEndpoints, nil) | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | } |