| 
									
										
										
										
											2016-08-06 04:48:31 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * Minio Cloud Storage, (C) 2016 Minio, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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-08-06 04:48:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 00:38:07 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 	"reflect" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Tests http.Header clone.
 | 
					
						
							|  |  |  | func TestCloneHeader(t *testing.T) { | 
					
						
							|  |  |  | 	headers := []http.Header{ | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-09-10 00:38:07 +08:00
										 |  |  | 			"Content-Type":   {"text/html; charset=UTF-8"}, | 
					
						
							|  |  |  | 			"Content-Length": {"0"}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-09-10 00:38:07 +08:00
										 |  |  | 			"Content-Length": {"0", "1", "2"}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-09-10 00:38:07 +08:00
										 |  |  | 			"Expires":          {"-1"}, | 
					
						
							|  |  |  | 			"Content-Length":   {"0"}, | 
					
						
							|  |  |  | 			"Content-Encoding": {"gzip"}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for i, header := range headers { | 
					
						
							|  |  |  | 		clonedHeader := cloneHeader(header) | 
					
						
							|  |  |  | 		if !reflect.DeepEqual(header, clonedHeader) { | 
					
						
							|  |  |  | 			t.Errorf("Test %d failed", i+1) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-08-06 04:48:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 16:59:28 +08:00
										 |  |  | // Tests maximum object size.
 | 
					
						
							|  |  |  | func TestMaxObjectSize(t *testing.T) { | 
					
						
							|  |  |  | 	sizes := []struct { | 
					
						
							|  |  |  | 		isMax bool | 
					
						
							|  |  |  | 		size  int64 | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// Test - 1 - maximum object size.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 			maxObjectSize + 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// Test - 2 - not maximum object size.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 			maxObjectSize - 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for i, s := range sizes { | 
					
						
							|  |  |  | 		isMax := isMaxObjectSize(s.size) | 
					
						
							|  |  |  | 		if isMax != s.isMax { | 
					
						
							|  |  |  | 			t.Errorf("Test %d: Expected %t, got %t", i+1, s.isMax, isMax) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Tests minimum allowed part size.
 | 
					
						
							|  |  |  | func TestMinAllowedPartSize(t *testing.T) { | 
					
						
							|  |  |  | 	sizes := []struct { | 
					
						
							|  |  |  | 		isMin bool | 
					
						
							|  |  |  | 		size  int64 | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// Test - 1 - within minimum part size.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 			minPartSize + 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// Test - 2 - smaller than minimum part size.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 			minPartSize - 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, s := range sizes { | 
					
						
							|  |  |  | 		isMin := isMinAllowedPartSize(s.size) | 
					
						
							|  |  |  | 		if isMin != s.isMin { | 
					
						
							|  |  |  | 			t.Errorf("Test %d: Expected %t, got %t", i+1, s.isMin, isMin) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Tests maximum allowed part number.
 | 
					
						
							|  |  |  | func TestMaxPartID(t *testing.T) { | 
					
						
							|  |  |  | 	sizes := []struct { | 
					
						
							|  |  |  | 		isMax bool | 
					
						
							|  |  |  | 		partN int | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// Test - 1 part number within max part number.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 			maxPartID - 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// Test - 2 part number bigger than max part number.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 			maxPartID + 1, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, s := range sizes { | 
					
						
							|  |  |  | 		isMax := isMaxPartID(s.partN) | 
					
						
							|  |  |  | 		if isMax != s.isMax { | 
					
						
							|  |  |  | 			t.Errorf("Test %d: Expected %t, got %t", i+1, s.isMax, isMax) | 
					
						
							| 
									
										
										
										
											2016-08-07 14:53:10 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-08-06 04:48:31 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |