aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlexandre Garand <alexandre.garand@fretlink.com>2019-07-09 10:20:59 +0200
committerAlexandre Garand <alexandre.garand@fretlink.com>2019-07-09 11:39:18 +0200
commit5976bba0b5dd67d2169641a5c3dab935155fb885 (patch)
treec06237305a4e1280dfe7c9fe08c8bc15bb14ae63
parentdbbb014f494c502d8ac26437acd02412ee275b5a (diff)
downloadterraform-provider-mailgun-5976bba0b5dd67d2169641a5c3dab935155fb885.tar.gz
terraform-provider-mailgun-5976bba0b5dd67d2169641a5c3dab935155fb885.tar.zst
terraform-provider-mailgun-5976bba0b5dd67d2169641a5c3dab935155fb885.zip
fix the tests
the ips are now fetched correctly a sleep was put in the destroy check to ensure that the api have time to destroy before it is checked
-rw-r--r--mailgun/resource_mailgun_domain.go18
-rw-r--r--mailgun/resource_mailgun_domain_test.go7
2 files changed, 18 insertions, 7 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go
index 86531c6..e2bfe73 100644
--- a/mailgun/resource_mailgun_domain.go
+++ b/mailgun/resource_mailgun_domain.go
@@ -366,7 +366,7 @@ func DeleteDomain(d *schema.ResourceData, meta interface{}) error {
366 366
367func ReadDomain(d *schema.ResourceData, meta interface{}) error { 367func ReadDomain(d *schema.ResourceData, meta interface{}) error {
368 mg := meta.(*mailgun.MailgunImpl) 368 mg := meta.(*mailgun.MailgunImpl)
369 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 369 ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
370 defer cancel() 370 defer cancel()
371 domainName := d.Id() 371 domainName := d.Id()
372 mg = mailgun.NewMailgun(domainName, mg.APIKey()) 372 mg = mailgun.NewMailgun(domainName, mg.APIKey())
@@ -425,9 +425,7 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error {
425 d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter) 425 d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter)
426 d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter) 426 d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter)
427 427
428 time.Sleep(25 * time.Second) 428 ipAddress, err := getIps(ctx, mg)
429
430 ipAddress, err := mg.ListDomainIPS(ctx)
431 429
432 if err != nil { 430 if err != nil {
433 return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err) 431 return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err)
@@ -493,3 +491,15 @@ func ImportStatePassthroughDomain(d *schema.ResourceData, meta interface{}) ([]*
493 } 491 }
494 return []*schema.ResourceData{d}, nil 492 return []*schema.ResourceData{d}, nil
495} 493}
494
495func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){
496 start := time.Now()
497 t := time.Now()
498 ipAddress, err := mg.ListDomainIPS(ctx)
499 for (err != nil && t.Sub(start)< 120 * time.Second) {
500 ipAddress, err = mg.ListDomainIPS(ctx)
501 time.Sleep(5 * time.Second)
502 t = time.Now()
503 }
504 return ipAddress, err
505}
diff --git a/mailgun/resource_mailgun_domain_test.go b/mailgun/resource_mailgun_domain_test.go
index 952e013..a129b1f 100644
--- a/mailgun/resource_mailgun_domain_test.go
+++ b/mailgun/resource_mailgun_domain_test.go
@@ -21,7 +21,7 @@ type fullDomain struct {
21} 21}
22 22
23func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, error) { 23func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, error) {
24 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 24 ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
25 defer cancel() 25 defer cancel()
26 mg = mailgun.NewMailgun(domainName, mg.APIKey()) 26 mg = mailgun.NewMailgun(domainName, mg.APIKey())
27 27
@@ -42,7 +42,8 @@ func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, err
42 return nil, fmt.Errorf("Error Getting mailgun domain tracking Details for %s: Error: %s", domainName, err) 42 return nil, fmt.Errorf("Error Getting mailgun domain tracking Details for %s: Error: %s", domainName, err)
43 } 43 }
44 44
45 ipAddress, err := mg.ListDomainIPS(ctx) 45 ipAddress, err := getIps(ctx, mg)
46
46 if err != nil { 47 if err != nil {
47 return nil, fmt.Errorf("Error Getting mailgun domain ips2 for %s: Error: %s", domainName, err) 48 return nil, fmt.Errorf("Error Getting mailgun domain ips2 for %s: Error: %s", domainName, err)
48 } 49 }
@@ -209,7 +210,7 @@ func testAccDomainCheckDestroy(domain *fullDomain) resource.TestCheckFunc {
209 mg := testAccProvider.Meta().(*mailgun.MailgunImpl) 210 mg := testAccProvider.Meta().(*mailgun.MailgunImpl)
210 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 211 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
211 defer cancel() 212 defer cancel()
212 213 time.Sleep(5 * time.Second)
213 _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name) 214 _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name)
214 if err == nil { 215 if err == nil {
215 return fmt.Errorf("domain still exists") 216 return fmt.Errorf("domain still exists")