Skip to content

Commit

Permalink
Force to use the wildcard cert in test
Browse files Browse the repository at this point in the history
  • Loading branch information
fformica committed Jun 6, 2024
1 parent 0dab8a1 commit f8be1e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ns1/resource_redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 25 additions & 1 deletion ns1/resource_redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ns1

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand All @@ -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"}),
),
},
{
Expand All @@ -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"}),
),
},
},
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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" {
Expand Down Expand Up @@ -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
}
}

0 comments on commit f8be1e2

Please sign in to comment.