这是indexloc提供的服务,不要输入任何密码
Skip to content

add missing_files test when creating deployments #263

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

Merged
merged 5 commits into from
Jan 30, 2025
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
64 changes: 64 additions & 0 deletions vercel/resource_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package vercel_test
import (
"context"
"fmt"
"math/rand"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -249,6 +251,49 @@ 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_DeploymentWithMissingFilesPath(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("<html>\n<body>\nRandom integer: %d\n</body>\n</html>\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: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()),
Check: resource.ComposeAggregateTestCheckFunc(
testAccDeploymentExists("vercel_deployment.test", ""),
),
},
},
})
}

func testAccDeploymentConfigWithNoDeployment(projectSuffix, teamID string) string {
return fmt.Sprintf(`
resource "vercel_project" "test" {
Expand Down Expand Up @@ -401,3 +446,22 @@ resource "vercel_deployment" "bitbucket" {
}
`, projectSuffix, testGithubRepo(), testBitbucketRepo(), teamID)
}

func testAccWithDirectoryUpload(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)
}
Loading