| 
									
										
										
										
											2018-10-03 18:55:01 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 18:31:35 +08:00
										 |  |  | 	"github.com/stretchr/testify/assert" | 
					
						
							| 
									
										
										
										
											2018-10-03 18:55:01 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestDataProxy(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2020-11-17 18:31:35 +08:00
										 |  |  | 	testCases := []struct { | 
					
						
							|  |  |  | 		desc      string | 
					
						
							|  |  |  | 		origPath  string | 
					
						
							|  |  |  | 		proxyPath string | 
					
						
							|  |  |  | 		exp       string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"Should append trailing slash to proxy path if original path has a trailing slash", | 
					
						
							|  |  |  | 			"/api/datasources/proxy/6/api/v1/query_range/", | 
					
						
							|  |  |  | 			"api/v1/query_range/", | 
					
						
							|  |  |  | 			"api/v1/query_range/", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"Should not append trailing slash to proxy path if original path doesn't have a trailing slash", | 
					
						
							|  |  |  | 			"/api/datasources/proxy/6/api/v1/query_range", | 
					
						
							|  |  |  | 			"api/v1/query_range", | 
					
						
							|  |  |  | 			"api/v1/query_range", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for _, tc := range testCases { | 
					
						
							|  |  |  | 		t.Run(tc.desc, func(t *testing.T) { | 
					
						
							|  |  |  | 			assert.Equal(t, tc.exp, ensureProxyPathTrailingSlash(tc.origPath, tc.proxyPath)) | 
					
						
							| 
									
										
										
										
											2018-10-03 18:55:01 +08:00
										 |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2020-11-17 18:31:35 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-03 18:55:01 +08:00
										 |  |  | } |