| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | package pprof | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 18:14:41 +02:00
										 |  |  | 	"github.com/coredns/caddy" | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestPProf(t *testing.T) { | 
					
						
							|  |  |  | 	tests := []struct { | 
					
						
							|  |  |  | 		input     string | 
					
						
							|  |  |  | 		shouldErr bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{`pprof`, false}, | 
					
						
							| 
									
										
										
										
											2017-04-24 10:27:26 -04:00
										 |  |  | 		{`pprof 1.2.3.4:1234`, false}, | 
					
						
							|  |  |  | 		{`pprof :1234`, false}, | 
					
						
							| 
									
										
										
										
											2019-03-29 02:37:17 -04:00
										 |  |  | 		{`pprof :1234 -1`, true}, | 
					
						
							|  |  |  | 		{`pprof { | 
					
						
							|  |  |  |                 }`, false}, | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 		{`pprof /foo`, true}, | 
					
						
							|  |  |  | 		{`pprof { | 
					
						
							|  |  |  |             a b | 
					
						
							|  |  |  |         }`, true}, | 
					
						
							| 
									
										
										
										
											2019-03-29 02:37:17 -04:00
										 |  |  | 		{`pprof { block | 
					
						
							|  |  |  |                 }`, false}, | 
					
						
							| 
									
										
										
										
											2019-04-29 10:51:45 -07:00
										 |  |  | 		{`pprof :1234 { | 
					
						
							| 
									
										
										
										
											2019-03-29 02:37:17 -04:00
										 |  |  |                    block 20 | 
					
						
							|  |  |  |                 }`, false}, | 
					
						
							| 
									
										
										
										
											2019-04-29 10:51:45 -07:00
										 |  |  | 		{`pprof { | 
					
						
							| 
									
										
										
										
											2019-03-29 02:37:17 -04:00
										 |  |  |                    block 20 30 | 
					
						
							|  |  |  |                 }`, true}, | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 		{`pprof | 
					
						
							|  |  |  |           pprof`, true}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for i, test := range tests { | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		c := caddy.NewTestController("dns", test.input) | 
					
						
							|  |  |  | 		err := setup(c) | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 		if test.shouldErr && err == nil { | 
					
						
							|  |  |  | 			t.Errorf("Test %v: Expected error but found nil", i) | 
					
						
							|  |  |  | 		} else if !test.shouldErr && err != nil { | 
					
						
							|  |  |  | 			t.Errorf("Test %v: Expected no error but found error: %v", i, err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |