| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | package route53 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/aws/aws-sdk-go/aws/credentials" | 
					
						
							|  |  |  | 	"github.com/aws/aws-sdk-go/service/route53/route53iface" | 
					
						
							| 
									
										
										
										
											2019-07-03 09:04:47 +08:00
										 |  |  | 	"github.com/caddyserver/caddy" | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSetupRoute53(t *testing.T) { | 
					
						
							|  |  |  | 	f := func(credential *credentials.Credentials) 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-02-23 22:32:58 +05:30
										 |  |  | 		{`route53 example.org { | 
					
						
							|  |  |  | 	}`, true}, | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | 		if err := setup(c, f); (err == nil) == test.expectedError { | 
					
						
							|  |  |  | 			t.Errorf("Unexpected errors: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-10 10:55:54 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-15 09:59:29 -08:00
										 |  |  | } |