From f8be1e2187a256f1ed13fe584b4200ddff280ac3 Mon Sep 17 00:00:00 2001 From: Ferdinando Formica Date: Thu, 6 Jun 2024 11:57:44 +0100 Subject: [PATCH] Force to use the wildcard cert in test --- ns1/resource_redirect.go | 8 ++++---- ns1/resource_redirect_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ns1/resource_redirect.go b/ns1/resource_redirect.go index de1d0e66..5d08a7b5 100644 --- a/ns1/resource_redirect.go +++ b/ns1/resource_redirect.go @@ -51,15 +51,15 @@ func redirectConfigResource() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "certificate_id": { - Type: schema.TypeString, - Computed: true, - }, "last_updated": { Type: schema.TypeInt, Computed: true, }, // Optional + "certificate_id": { + Type: schema.TypeString, + Optional: true, + }, "forwarding_mode": { Type: schema.TypeString, Optional: true, diff --git a/ns1/resource_redirect_test.go b/ns1/resource_redirect_test.go index f2500f26..bf453dcc 100644 --- a/ns1/resource_redirect_test.go +++ b/ns1/resource_redirect_test.go @@ -2,6 +2,7 @@ package ns1 import ( "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -27,6 +28,7 @@ func TestAccRedirectConfig_basic(t *testing.T) { testAccCheckRedirectConfigExists("ns1_redirect.it", &redirect), testAccCheckRedirectConfigDomain(&redirect, "test."+domainName), testAccCheckRedirectConfigFwType(&redirect, "masking"), + testAccCheckRedirectConfigTags(&redirect, []string{"test", "it"}), ), }, { @@ -35,6 +37,7 @@ func TestAccRedirectConfig_basic(t *testing.T) { testAccCheckRedirectConfigExists("ns1_redirect.it", &redirect), testAccCheckRedirectConfigDomain(&redirect, "test."+domainName), testAccCheckRedirectConfigFwType(&redirect, "permanent"), + testAccCheckRedirectConfigTags(&redirect, []string{"test"}), ), }, }, @@ -44,6 +47,7 @@ func TestAccRedirectConfig_basic(t *testing.T) { func testAccRedirectBasic(rString string) string { return fmt.Sprintf(` resource "ns1_redirect" "it" { + certificate_id = "${ns1_redirect_certificate.example.id}" domain = "test.${ns1_zone.test.zone}" path = "/from/path/*" target = "https://url.com/target/path" @@ -68,6 +72,7 @@ resource "ns1_zone" "test" { func testAccRedirectUpdated(rString string) string { return fmt.Sprintf(` resource "ns1_redirect" "it" { + certificate_id = "${ns1_redirect_certificate.example.id}" domain = "test.${ns1_zone.test.zone}" path = "/from/path/*" target = "https://url.com/target/path" @@ -76,7 +81,7 @@ resource "ns1_redirect" "it" { https_enabled = true https_forced = true query_forwarding = true - tags = [ "test", "it" ] + tags = [ "test" ] } resource "ns1_redirect_certificate" "example" { @@ -172,3 +177,22 @@ func testAccCheckRedirectConfigFwType(cfg *redirect.Configuration, expected stri return nil } } + +func testAccCheckRedirectConfigTags(cfg *redirect.Configuration, expected []string) resource.TestCheckFunc { + return func(s *terraform.State) error { + diff := false + if len(cfg.Tags) != len(expected) { + diff = true + } else { + for i, _ := range expected { + if cfg.Tags[i] != expected[i] { + diff = true + } + } + } + if diff { + return fmt.Errorf("Name: got: %s want: %s", strings.Join(cfg.Tags, ","), strings.Join(expected, ",")) + } + return nil + } +}