Skip to content

Commit 2c51cc0

Browse files
authored
add missing_files test when creating deployments (#263)
* add missing_files test when creating deployments * change test name * change test name * join common lines * gofmt
1 parent bb4cd02 commit 2c51cc0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

vercel/resource_deployment_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package vercel_test
33
import (
44
"context"
55
"fmt"
6+
"math/rand"
7+
"os"
68
"strings"
79
"testing"
810

@@ -249,6 +251,49 @@ func TestAcc_DeploymentWithGitSource(t *testing.T) {
249251
})
250252
}
251253

254+
// This test executes the path where we handle the `missing_files` error.
255+
// To do that, we need to create a new file with random contents to trigger the
256+
// `missing_files` error. Otherwise, if the contents do not change, we will use
257+
// the cached deployments files
258+
func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) {
259+
tmpFilePath := "../vercel/examples/one/random-file.html"
260+
261+
createRandomFilePreConfig := func(t *testing.T) {
262+
min := 1
263+
max := 1_000_000
264+
randomInt := rand.Intn(max-min) + min
265+
266+
fileBody := []byte(fmt.Sprintf("<html>\n<body>\nRandom integer: %d\n</body>\n</html>\n", randomInt))
267+
err := os.WriteFile(tmpFilePath, fileBody, 0644)
268+
if err != nil {
269+
t.Fatalf("Could not create the temporal file path %s. Error: %s", tmpFilePath, err)
270+
}
271+
}
272+
273+
cleanup := func(t *testing.T) {
274+
if err := os.Remove(tmpFilePath); err != nil {
275+
t.Logf("Could not remove the random file %s. Error: %s", tmpFilePath, err)
276+
}
277+
}
278+
defer cleanup(t)
279+
280+
projectSuffix := acctest.RandString(16)
281+
resource.Test(t, resource.TestCase{
282+
PreCheck: func() { testAccPreCheck(t) },
283+
CheckDestroy: noopDestroyCheck,
284+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
285+
Steps: []resource.TestStep{
286+
{
287+
PreConfig: func() { createRandomFilePreConfig(t) },
288+
Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()),
289+
Check: resource.ComposeAggregateTestCheckFunc(
290+
testAccDeploymentExists("vercel_deployment.test", ""),
291+
),
292+
},
293+
},
294+
})
295+
}
296+
252297
func testAccDeploymentConfigWithNoDeployment(projectSuffix, teamID string) string {
253298
return fmt.Sprintf(`
254299
resource "vercel_project" "test" {
@@ -401,3 +446,22 @@ resource "vercel_deployment" "bitbucket" {
401446
}
402447
`, projectSuffix, testGithubRepo(), testBitbucketRepo(), teamID)
403448
}
449+
450+
func testAccWithDirectoryUpload(projectSuffix, teamID string) string {
451+
return fmt.Sprintf(`
452+
resource "vercel_project" "test" {
453+
name = "test-acc-deployment-%[1]s"
454+
%[2]s
455+
}
456+
457+
data "vercel_project_directory" "test" {
458+
path = "../vercel/examples/one"
459+
}
460+
461+
resource "vercel_deployment" "test" {
462+
project_id = vercel_project.test.id
463+
%[2]s
464+
files = data.vercel_project_directory.test.files
465+
path_prefix = data.vercel_project_directory.test.path
466+
}`, projectSuffix, teamID)
467+
}

0 commit comments

Comments
 (0)