From c7e8544c1d79d0823261ff3ada622a1992811d7a Mon Sep 17 00:00:00 2001 From: Marc Codina Date: Mon, 27 Jan 2025 12:54:03 +0100 Subject: [PATCH 1/5] add missing_files test when creating deployments --- vercel/resource_deployment_test.go | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index f943d119..ab937193 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -3,6 +3,8 @@ package vercel_test import ( "context" "fmt" + "math/rand" + "os" "strings" "testing" @@ -249,6 +251,50 @@ func TestAcc_DeploymentWithGitSource(t *testing.T) { }) } +// This test executes the path where we handle the `missing_files` error. +// To do that, we need to create a new file with random contents to trigger the +// `missing_files` error. Otherwise, if the contents do not change, we will use +// the cached deployments files +func TestAcc_DeploymentWithLargeFile(t *testing.T) { + tmpFilePath := "../vercel/examples/one/random-file.html" + + createRandomFilePreConfig := func(t *testing.T) { + min := 1 + max := 1_000_000 + randomInt := rand.Intn(max - min) + min + + fileBody := []byte(fmt.Sprintf("\n\nRandom integer: %d\n\n\n", randomInt)) + + err := os.WriteFile(tmpFilePath, fileBody, 0644) + if err != nil { + t.Fatalf("Could not create the temporal file path %s. Error: %s", tmpFilePath, err) + } + } + + cleanup := func(t *testing.T) { + if err := os.Remove(tmpFilePath); err != nil { + t.Logf("Could not remove the random file %s. Error: %s", tmpFilePath, err) + } + } + defer cleanup(t) + + projectSuffix := acctest.RandString(16) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + CheckDestroy: noopDestroyCheck, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + PreConfig: func() { createRandomFilePreConfig(t) }, + Config: testAccWithLargeFile(projectSuffix, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + testAccDeploymentExists("vercel_deployment.test", ""), + ), + }, + }, + }) +} + func testAccDeploymentConfigWithNoDeployment(projectSuffix, teamID string) string { return fmt.Sprintf(` resource "vercel_project" "test" { @@ -401,3 +447,22 @@ resource "vercel_deployment" "bitbucket" { } `, projectSuffix, testGithubRepo(), testBitbucketRepo(), teamID) } + +func testAccWithLargeFile(projectSuffix, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "test" { + name = "test-acc-deployment-%[1]s" + %[2]s +} + +data "vercel_project_directory" "test" { + path = "../vercel/examples/one" + } + +resource "vercel_deployment" "test" { + project_id = vercel_project.test.id + %[2]s + files = data.vercel_project_directory.test.files + path_prefix = data.vercel_project_directory.test.path +}`, projectSuffix, teamID) +} From 4217489b1b60fe85fccd22a09514735ab9589d5d Mon Sep 17 00:00:00 2001 From: Marc Codina Date: Mon, 27 Jan 2025 12:55:23 +0100 Subject: [PATCH 2/5] change test name --- vercel/resource_deployment_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index ab937193..738b3066 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -286,7 +286,7 @@ func TestAcc_DeploymentWithLargeFile(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { createRandomFilePreConfig(t) }, - Config: testAccWithLargeFile(projectSuffix, teamIDConfig()), + Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()), Check: resource.ComposeAggregateTestCheckFunc( testAccDeploymentExists("vercel_deployment.test", ""), ), @@ -448,7 +448,7 @@ resource "vercel_deployment" "bitbucket" { `, projectSuffix, testGithubRepo(), testBitbucketRepo(), teamID) } -func testAccWithLargeFile(projectSuffix, teamID string) string { +func testAccWithDirectoryUpload(projectSuffix, teamID string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-deployment-%[1]s" From f19cff469548c253e5b16ab477d03c4aff6f2c74 Mon Sep 17 00:00:00 2001 From: Marc Codina Date: Mon, 27 Jan 2025 12:55:58 +0100 Subject: [PATCH 3/5] change test name --- vercel/resource_deployment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index 738b3066..361a72a4 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -255,7 +255,7 @@ func TestAcc_DeploymentWithGitSource(t *testing.T) { // To do that, we need to create a new file with random contents to trigger the // `missing_files` error. Otherwise, if the contents do not change, we will use // the cached deployments files -func TestAcc_DeploymentWithLargeFile(t *testing.T) { +func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) { tmpFilePath := "../vercel/examples/one/random-file.html" createRandomFilePreConfig := func(t *testing.T) { From e13ad1789a546d873b30385d59e29f1df040ed9e Mon Sep 17 00:00:00 2001 From: Marc Codina Date: Mon, 27 Jan 2025 12:57:05 +0100 Subject: [PATCH 4/5] join common lines --- vercel/resource_deployment_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index 361a72a4..04cb8333 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -264,7 +264,6 @@ func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) { randomInt := rand.Intn(max - min) + min fileBody := []byte(fmt.Sprintf("\n\nRandom integer: %d\n\n\n", randomInt)) - err := os.WriteFile(tmpFilePath, fileBody, 0644) if err != nil { t.Fatalf("Could not create the temporal file path %s. Error: %s", tmpFilePath, err) From 620835498c5242f11b77a4763d08495195260ec3 Mon Sep 17 00:00:00 2001 From: Marc Codina Date: Mon, 27 Jan 2025 13:04:50 +0100 Subject: [PATCH 5/5] gofmt --- vercel/resource_deployment_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index 04cb8333..08ee565d 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -261,7 +261,7 @@ func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) { createRandomFilePreConfig := func(t *testing.T) { min := 1 max := 1_000_000 - randomInt := rand.Intn(max - min) + min + randomInt := rand.Intn(max-min) + min fileBody := []byte(fmt.Sprintf("\n\nRandom integer: %d\n\n\n", randomInt)) err := os.WriteFile(tmpFilePath, fileBody, 0644) @@ -285,7 +285,7 @@ func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: func() { createRandomFilePreConfig(t) }, - Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()), + Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()), Check: resource.ComposeAggregateTestCheckFunc( testAccDeploymentExists("vercel_deployment.test", ""), ),