| 
									
										
										
										
											2016-06-27 10:48:02 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-06-27 10:48:02 +08: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-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-06-27 10:48:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 18:13:44 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 	"reflect" | 
					
						
							| 
									
										
										
										
											2016-06-29 18:13:44 +08:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-06-27 10:48:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | // Sort valid disks info.
 | 
					
						
							|  |  |  | func TestSortingValidDisks(t *testing.T) { | 
					
						
							|  |  |  | 	testCases := []struct { | 
					
						
							| 
									
										
										
										
											2018-05-23 18:11:29 +08:00
										 |  |  | 		disksInfo      []DiskInfo | 
					
						
							|  |  |  | 		validDisksInfo []DiskInfo | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 	}{ | 
					
						
							|  |  |  | 		// One of the disks is offline.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-23 18:11:29 +08:00
										 |  |  | 			disksInfo: []DiskInfo{ | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 				{Total: 150, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 0, Free: 0}, | 
					
						
							|  |  |  | 				{Total: 200, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 100, Free: 10}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-05-23 18:11:29 +08:00
										 |  |  | 			validDisksInfo: []DiskInfo{ | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 				{Total: 100, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 150, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 200, Free: 10}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// All disks are online.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-23 18:11:29 +08:00
										 |  |  | 			disksInfo: []DiskInfo{ | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 				{Total: 150, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 200, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 100, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 115, Free: 10}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-05-23 18:11:29 +08:00
										 |  |  | 			validDisksInfo: []DiskInfo{ | 
					
						
							| 
									
										
										
										
											2016-10-18 05:31:33 +08:00
										 |  |  | 				{Total: 100, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 115, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 150, Free: 10}, | 
					
						
							|  |  |  | 				{Total: 200, Free: 10}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, testCase := range testCases { | 
					
						
							|  |  |  | 		validDisksInfo := sortValidDisksInfo(testCase.disksInfo) | 
					
						
							|  |  |  | 		if !reflect.DeepEqual(validDisksInfo, testCase.validDisksInfo) { | 
					
						
							|  |  |  | 			t.Errorf("Test %d: Expected %#v, Got %#v", i+1, testCase.validDisksInfo, validDisksInfo) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |