| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | package platform_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-11-06 12:23:21 +01:00
										 |  |  | 	"os" | 
					
						
							|  |  |  | 	"path/filepath" | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	. "v2ray.com/core/common/platform" | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 	. "v2ray.com/ext/assert" | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNormalizeEnvName(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 	assert := With(t) | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cases := []struct { | 
					
						
							|  |  |  | 		input  string | 
					
						
							|  |  |  | 		output string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input:  "a", | 
					
						
							|  |  |  | 			output: "A", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input:  "a.a", | 
					
						
							|  |  |  | 			output: "A_A", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input:  "A.A.B", | 
					
						
							|  |  |  | 			output: "A_A_B", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for _, test := range cases { | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 		assert(NormalizeEnvName(test.input), Equals, test.output) | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestEnvFlag(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 	assert := With(t) | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 	assert(EnvFlag{ | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | 		Name: "xxxxx.y", | 
					
						
							| 
									
										
										
										
											2017-10-24 16:15:35 +02:00
										 |  |  | 	}.GetValueAsInt(10), Equals, 10) | 
					
						
							| 
									
										
										
										
											2017-05-26 01:11:38 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-06 12:23:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestGetAssetLocation(t *testing.T) { | 
					
						
							|  |  |  | 	assert := With(t) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	exec, err := os.Executable() | 
					
						
							|  |  |  | 	assert(err, IsNil) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	loc := GetAssetLocation("t") | 
					
						
							|  |  |  | 	assert(filepath.Dir(loc), Equals, filepath.Dir(exec)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	os.Setenv("v2ray.location.asset", "/v2ray") | 
					
						
							|  |  |  | 	assert(GetAssetLocation("t"), Equals, "/v2ray/t") | 
					
						
							|  |  |  | } |