Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(zone): fix data source examples #4586

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 36 additions & 49 deletions internal/services/zone/data_source_zone_test.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,42 @@
package zone_test

// func TestAccCloudflareZone_PreventZoneIdAndNameConflicts(t *testing.T) {
// t.Parallel()
// rnd := utils.GenerateRandomResourceName()
// resource.Test(t, resource.TestCase{
// PreCheck: func() { acctest.TestAccPreCheck(t) },
// ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: testAccCloudflareZoneConfigConflictingFields(rnd),
// ExpectError: regexp.MustCompile(regexp.QuoteMeta("only one of `name,zone_id` can be specified")),
// },
// },
// })
// }
import (
"fmt"
"testing"

// func testAccCloudflareZoneConfigConflictingFields(rnd string) string {
// return fmt.Sprintf(`
// data "cloudflare_zone" "%[1]s" {
// name = "terraform.cfapi.net"
// zone_id = "abc123"
// }
// `, rnd)
// }
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

// func TestAccCloudflareZone_NameLookup(t *testing.T) {
// t.Parallel()
// rnd := utils.GenerateRandomResourceName()
// name := fmt.Sprintf("data.cloudflare_zone.%s", rnd)
func TestAccCloudflareZone_NameLookup(t *testing.T) {
t.Parallel()
rnd := utils.GenerateRandomResourceName()
name := fmt.Sprintf("data.cloudflare_zone.%s", rnd)

// resource.Test(t, resource.TestCase{
// PreCheck: func() { acctest.TestAccPreCheck(t) },
// ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: testAccCloudflareZoneConfigBasic(rnd),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckCloudflareZonesDataSourceID(name),
// resource.TestCheckResourceAttr(name, "name", "terraform.cfapi.net"),
// resource.TestCheckResourceAttr(name, consts.ZoneIDSchemaKey, acctest.TestAccCloudflareZoneID),
// resource.TestCheckResourceAttr(name, "status", "active"),
// ),
// },
// },
// })
// }
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccCloudflareZoneConfigBasic(rnd),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", "terraform.cfapi.net"),
resource.TestCheckResourceAttr(name, consts.IDSchemaKey, acctest.TestAccCloudflareZoneID),
resource.TestCheckResourceAttr(name, "status", "active"),
),
},
},
})
}

// func testAccCloudflareZoneConfigBasic(rnd string) string {
// return fmt.Sprintf(`
// data "cloudflare_zone" "%[1]s" {
// name = "terraform.cfapi.net"
// }
// `, rnd)
// }
func testAccCloudflareZoneConfigBasic(rnd string) string {
return fmt.Sprintf(`
data "cloudflare_zone" "%[1]s" {
filter = {
name = "terraform.cfapi.net"
}
}
`, rnd)
}
Loading