Skip to content

Commit

Permalink
start fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Aug 26, 2022
1 parent 8e7d2d8 commit 59762b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
6 changes: 3 additions & 3 deletions internal/provider/resource_cloudflare_pages_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package provider

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func testPagesDomainConfig(resourceID, accountID, projectName, domain string) string {
Expand All @@ -17,12 +18,11 @@ func testPagesDomainConfig(resourceID, accountID, projectName, domain string) st
`, resourceID, accountID, projectName, domain)
}

func TestAccTestPagesDomain(t *testing.T) {
func TestAccTestPagesDomain_Basic(t *testing.T) {
rnd := generateRandomResourceName()
name := "cloudflare_pages_domain." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")

//resourceCloudflarePagesDomain
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Expand Down
62 changes: 41 additions & 21 deletions internal/provider/resource_cloudflare_pages_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,79 @@ package provider

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func testPagesProjectConfig(resourceID, accountID, projectName string) string {
return fmt.Sprintf(`
resource "cloudflare_pages_domain" "%[1]s" {
resource "cloudflare_pages_project" "%[1]s" {
account_id = "%[2]s"
project_name = "%[3]s"
name = "%[3]s"
source {
type = "github"
config {
owner = "jacobbednarz"
repo_name = "terraform-acc-pages-placeholder"
production_branch = "main"
}
}
}
`, resourceID, accountID, projectName)
}

func testPagesProjectBuildConfig(resourceID, accountID, projectName string) string {
return fmt.Sprintf(`
resource "cloudflare_pages_domain" "%[1]s" {
resource "cloudflare_pages_project" "%[1]s" {
account_id = "%[2]s"
project_name = "%[3]s"
build_config = {
build_command = "npm run build",
name = "%[3]s"
source {
type = "github"
config {
owner = "jacobbednarz"
repo_name = "terraform-acc-pages-placeholder"
production_branch = "main"
}
}
build_config {
build_command = "npm run build"
destination_dir = "build"
root_dir = "/"
web_analytics_tag = "cee1c73f6e4743d0b5e6bb1a0bcaabcc"
web_analytics_token = "021e1057c18547eca7b79f2516f06o7x"
}
}
`, resourceID, accountID, projectName)
}

func testPagesProjectDeploymentConfig(resourceID, accountID, projectName string) string {
return fmt.Sprintf(`
resource "cloudflare_pages_domain" "%[1]s" {
resource "cloudflare_pages_project" "%[1]s" {
account_id = "%[2]s"
project_name = "%[3]s"
name = "%[3]s"
source {
type = "github"
config {
owner = "jacobbednarz"
repo_name = "terraform-acc-pages-placeholder"
production_branch = "main"
}
}
deployment_configs {
preview {
environment_variables = {
ENVIRONMENT = "preview"
}
compatibility_date = "2022-08-15"
compatibility_flags = ["preview_flag"]
},
}
production {
environment_variables = {
ENVIRONMENT = "production"
}
compatibility_date = "2022-08-15"
compatibility_flags = ["preview_flag"]
}
Expand All @@ -61,16 +87,14 @@ func TestAccTestPagesProject(t *testing.T) {
name := "cloudflare_pages_project." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")

//resourceCloudflarePagesProject
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testPagesProjectConfig(rnd, accountID, "this-is-my-project-01"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "project_name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "domain", "example.com"),
resource.TestCheckResourceAttr(name, "name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "account_id", accountID),
),
},
Expand All @@ -83,16 +107,14 @@ func TestAccTestPagesProjectBuildConfig(t *testing.T) {
name := "cloudflare_pages_project." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")

//resourceCloudflarePagesProject
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testPagesProjectBuildConfig(rnd, accountID, "this-is-my-project-01"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "project_name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "domain", "example.com"),
resource.TestCheckResourceAttr(name, "name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "account_id", accountID),
resource.TestCheckResourceAttr(name, "build_config.0.build_command", "npm run build"),
resource.TestCheckResourceAttr(name, "build_config.0.destination_dir", "build"),
Expand All @@ -110,16 +132,14 @@ func TestAccTestPagesProjectDeploymentConfig(t *testing.T) {
name := "cloudflare_pages_project." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")

//resourceCloudflarePagesProject
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testPagesProjectDeploymentConfig(rnd, accountID, "this-is-my-project-01"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "project_name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "domain", "example.com"),
resource.TestCheckResourceAttr(name, "name", "this-is-my-project-01"),
resource.TestCheckResourceAttr(name, "account_id", accountID),
resource.TestCheckResourceAttr(name, "deployment_configs.0.preview.0.environment_variables.0.ENVIRONMENT", "preview"),
resource.TestCheckResourceAttr(name, "deployment_configs.0.production.0.environment_variables.0.ENVIRONMENT", "production"),
Expand Down

0 comments on commit 59762b4

Please sign in to comment.