| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | package route53
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 18:14:41 +02:00
										 |  |  | 	"github.com/coredns/caddy"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 10:35:42 -07:00
										 |  |  | 	"github.com/aws/aws-sdk-go/aws/session"
 | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | 	"github.com/aws/aws-sdk-go/service/route53/route53iface"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSetupRoute53(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2022-05-09 10:35:42 -07:00
										 |  |  | 	f = func(opts session.Options) route53iface.Route53API {
 | 
					
						
							| 
									
										
										
										
											2018-09-17 11:19:07 -07:00
										 |  |  | 		return fakeRoute53{}
 | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		body          string
 | 
					
						
							|  |  |  | 		expectedError bool
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							|  |  |  | 		{`route53`, false},
 | 
					
						
							|  |  |  | 		{`route53 :`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  |     aws_access_key
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | }`, true},
 | 
					
						
							| 
									
										
										
										
											2019-07-02 16:23:47 +01:00
										 |  |  | 		{`route53 example.org:12345678 { }`, false},
 | 
					
						
							| 
									
										
										
										
											2018-11-02 22:07:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-02 16:23:47 +01:00
										 |  |  | 		{`route53 example.org:12345678 { }`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 { wat
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | }`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-17 11:19:07 -07:00
										 |  |  |     aws_access_key ACCESS_KEY_ID SEKRIT_ACCESS_KEY
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | }`, false},
 | 
					
						
							| 
									
										
										
										
											2018-10-10 10:55:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-25 11:41:05 -07:00
										 |  |  |     fallthrough
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | }`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:57:16 -07:00
										 |  |  | 		credentials
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 	}`, true},
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:57:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:57:16 -07:00
										 |  |  | 		credentials default
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 	}`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:57:16 -07:00
										 |  |  | 		credentials default credentials
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 	}`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:57:16 -07:00
										 |  |  | 		credentials default credentials extra-arg
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 	}`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 example.org:12345678 {
 | 
					
						
							|  |  |  | 	}`, true},
 | 
					
						
							| 
									
										
										
										
											2018-10-10 10:55:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-03 18:07:28 -07:00
										 |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  | 	refresh 90
 | 
					
						
							|  |  |  | }`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  | 	refresh 5m
 | 
					
						
							|  |  |  | }`, false},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  | 	refresh
 | 
					
						
							|  |  |  | }`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  | 	refresh foo
 | 
					
						
							|  |  |  | }`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  | 	refresh -1m
 | 
					
						
							|  |  |  | }`, true},
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 		{`route53 example.org {
 | 
					
						
							|  |  |  | 	}`, true},
 | 
					
						
							| 
									
										
										
										
											2021-11-08 14:45:45 +00:00
										 |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  |     aws_endpoint
 | 
					
						
							|  |  |  | }`, true},
 | 
					
						
							|  |  |  | 		{`route53 example.org:12345678 {
 | 
					
						
							|  |  |  |     aws_endpoint https://localhost
 | 
					
						
							|  |  |  | }`, false},
 | 
					
						
							| 
									
										
										
										
											2018-10-10 10:55:54 -07:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	for _, test := range tests {
 | 
					
						
							|  |  |  | 		c := caddy.NewTestController("dns", test.body)
 | 
					
						
							| 
									
										
										
										
											2019-10-03 07:21:11 +01:00
										 |  |  | 		if err := setup(c); (err == nil) == test.expectedError {
 | 
					
						
							| 
									
										
										
										
											2019-02-23 22:32:58 +05:30
										 |  |  | 			t.Errorf("Unexpected errors: %v", err)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-10-10 10:55:54 -07:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | }
 |