]> git.immae.eu Git - github/fretlink/terraform-provider-mailgun.git/commitdiff
add test for importation and fix importation for domain
authorAlexandre Garand <alexandre.garand@fretlink.com>
Mon, 8 Jul 2019 14:56:30 +0000 (16:56 +0200)
committerAlexandre Garand <alexandre.garand@fretlink.com>
Mon, 8 Jul 2019 14:56:30 +0000 (16:56 +0200)
mailgun/resource_mailgun_domain.go
mailgun/resource_mailgun_domain_test.go
mailgun/resource_mailgun_route_test.go

index 1fcba83bb1f104bbd270ec8304db6a6776d503a7..8ba0704dc7745082fe51ab834dc856cb3cf53c2f 100644 (file)
@@ -368,13 +368,20 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error {
        mg := meta.(*mailgun.MailgunImpl)
        ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
        defer cancel()
-       domainName := d.Get("name").(string)
+       domainName := d.Id()
        mg = mailgun.NewMailgun(domainName, mg.APIKey())
 
        domainResponse, err := mg.GetDomain(ctx, domainName)
        if err != nil {
                return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err)
        }
+       if _, ok := d.GetOk("dkim_key_size"); !ok {
+               d.Set("dkim_key_size", 1024)
+       }
+
+       if _, ok := d.GetOk("force_dkim_authority"); !ok {
+               d.Set("force_dkim_authority", false)
+       }
 
        d.Set("created_at", domainResponse.Domain.CreatedAt)
        d.Set("smtd_login", domainResponse.Domain.SMTPLogin)
index 6096c60844fc8c976511736ef5a8297680de31cb..952e0132aed7ee5f85bd7e0ecbb154125d5287c0 100644 (file)
@@ -105,6 +105,30 @@ func TestAccMailgunDomain_withUpdate(t *testing.T) {
        })
 }
 
+
+func TestDomain_importBasic(t *testing.T) {
+       var domain fullDomain
+
+       resource.Test(t, resource.TestCase{
+               PreCheck:     func() { testAccPreCheck(t) },
+               Providers:    testAccProviders,
+               CheckDestroy: testAccDomainCheckDestroy(&domain),
+               Steps: []resource.TestStep{
+                       {
+                               Config: interpolateTerraformTemplateDomain(testAccDomainConfig_import),
+                               Check: resource.ComposeTestCheckFunc(
+                                       testAccDomainCheckExists("mailgun_domain.exemple",&domain),
+                               ),
+                       },
+                       {
+                               ResourceName:      "mailgun_domain.exemple",
+                               ImportState:       true,
+                               ImportStateVerify: true,
+                       },
+               },
+       })
+}
+
 func testAccDomainCheckExists(rn string, domain *fullDomain) resource.TestCheckFunc {
        return func(s *terraform.State) error {
                rs, ok := s.RootModule().Resources[rn]
@@ -226,3 +250,8 @@ resource "mailgun_domain" "exemple" {
 
 }
 `
+const testAccDomainConfig_import = `
+resource "mailgun_domain" "exemple" {
+       name = "%s"
+}
+`
index 2d7b2210f89b2c7991bde143ef28f3fe318cd7c7..02d552adc032d69d14b6295da99ef458233ffcd7 100644 (file)
@@ -57,6 +57,29 @@ func TestAccMailgunRoute_withUpdate(t *testing.T) {
        })
 }
 
+func TestRoute_importBasic(t *testing.T) {
+       var route mailgun.Route
+
+       resource.Test(t, resource.TestCase{
+               PreCheck:     func() { testAccPreCheck(t) },
+               Providers:    testAccProviders,
+               CheckDestroy: testAccRouteCheckDestroy(&route),
+               Steps: []resource.TestStep{
+                       {
+                               Config: testAccRouteConfig_basic,
+                               Check: resource.ComposeTestCheckFunc(
+                                       testAccRouteCheckExists("mailgun_route.exemple",&route),
+                               ),
+                       },
+                       {
+                               ResourceName:      "mailgun_route.exemple",
+                               ImportState:       true,
+                               ImportStateVerify: true,
+                       },
+               },
+       })
+}
+
 func testAccRouteCheckExists(rn string, route *mailgun.Route) resource.TestCheckFunc {
        return func(s *terraform.State) error {
                rs, ok := s.RootModule().Resources[rn]