| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | package kubernetes
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 09:04:47 +08:00
										 |  |  | 	"github.com/caddyserver/caddy"
 | 
					
						
							| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestKubernetesParseReverseZone(t *testing.T) {
 | 
					
						
							|  |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		input         string   // Corefile data as string
 | 
					
						
							|  |  |  | 		expectedZones []string // expected count of defined zones.
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							|  |  |  | 		{`kubernetes coredns.local 10.0.0.0/16`, []string{"coredns.local.", "0.10.in-addr.arpa."}},
 | 
					
						
							| 
									
										
										
										
											2017-10-24 10:16:03 +01:00
										 |  |  | 		{`kubernetes coredns.local 10.0.0.0/17`, []string{"coredns.local.", "0.10.in-addr.arpa."}},
 | 
					
						
							| 
									
										
										
										
											2018-01-23 10:58:36 -05:00
										 |  |  | 		{`kubernetes coredns.local fd00:77:30::0/110`, []string{"coredns.local.", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa."}},
 | 
					
						
							| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, tc := range tests {
 | 
					
						
							|  |  |  | 		c := caddy.NewTestController("dns", tc.input)
 | 
					
						
							| 
									
										
										
										
											2018-02-12 14:27:16 -05:00
										 |  |  | 		k, err := kubernetesParse(c)
 | 
					
						
							| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | 		if err != nil {
 | 
					
						
							| 
									
										
										
										
											2017-08-18 14:45:20 +01:00
										 |  |  | 			t.Fatalf("Test %d: Expected no error, got %q", i, err)
 | 
					
						
							| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		zl := len(k.Zones)
 | 
					
						
							|  |  |  | 		if zl != len(tc.expectedZones) {
 | 
					
						
							| 
									
										
										
										
											2017-08-18 14:45:20 +01:00
										 |  |  | 			t.Errorf("Test %d: Expected kubernetes to be initialized with %d zones, found %d zones", i, len(tc.expectedZones), zl)
 | 
					
						
							| 
									
										
										
										
											2017-08-16 07:29:46 +01:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 		for i, z := range tc.expectedZones {
 | 
					
						
							|  |  |  | 			if k.Zones[i] != z {
 | 
					
						
							|  |  |  | 				t.Errorf("Test %d: Expected zones to be %q, got %q", i, z, k.Zones[i])
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 |