| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | package dnstap
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:00:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 18:14:41 +02:00
										 |  |  | 	"github.com/coredns/caddy"
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestConfig(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-09-01 14:07:21 +02:00
										 |  |  | 	tests := []struct {
 | 
					
						
							| 
									
										
										
										
											2020-11-05 14:37:16 +01:00
										 |  |  | 		in       string
 | 
					
						
							|  |  |  | 		endpoint string
 | 
					
						
							|  |  |  | 		full     bool
 | 
					
						
							|  |  |  | 		proto    string
 | 
					
						
							|  |  |  | 		fail     bool
 | 
					
						
							| 
									
										
										
										
											2017-09-01 14:07:21 +02:00
										 |  |  | 	}{
 | 
					
						
							| 
									
										
										
										
											2020-11-03 15:31:34 +01:00
										 |  |  | 		{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false},
 | 
					
						
							|  |  |  | 		{"dnstap unix://dnstap.sock", "dnstap.sock", false, "unix", false},
 | 
					
						
							|  |  |  | 		{"dnstap tcp://127.0.0.1:6000", "127.0.0.1:6000", false, "tcp", false},
 | 
					
						
							|  |  |  | 		{"dnstap", "fail", false, "tcp", true},
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2020-11-05 14:37:16 +01:00
										 |  |  | 	for i, tc := range tests {
 | 
					
						
							|  |  |  | 		c := caddy.NewTestController("dns", tc.in)
 | 
					
						
							|  |  |  | 		tap, err := parseConfig(c)
 | 
					
						
							|  |  |  | 		if tc.fail && err == nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("Test %d: expected test to fail: %s: %s", i, tc.in, err)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		if tc.fail {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if err != nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("Test %d: expected no error, got %s", i, err)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		if x := tap.io.(*dio).endpoint; x != tc.endpoint {
 | 
					
						
							|  |  |  | 			t.Errorf("Test %d: expected endpoint %s, got %s", i, tc.endpoint, x)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		if x := tap.io.(*dio).proto; x != tc.proto {
 | 
					
						
							|  |  |  | 			t.Errorf("Test %d: expected proto %s, got %s", i, tc.proto, x)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		if x := tap.IncludeRawMessage; x != tc.full {
 | 
					
						
							|  |  |  | 			t.Errorf("Test %d: expected IncludeRawMessage %t, got %t", i, tc.full, x)
 | 
					
						
							| 
									
										
										
										
											2017-09-01 14:07:21 +02:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-07-24 23:12:50 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 |