@@ -3,6 +3,8 @@ package vercel_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "math/rand"
7
+ "os"
6
8
"strings"
7
9
"testing"
8
10
@@ -249,6 +251,49 @@ func TestAcc_DeploymentWithGitSource(t *testing.T) {
249
251
})
250
252
}
251
253
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>\n Random 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
+
252
297
func testAccDeploymentConfigWithNoDeployment (projectSuffix , teamID string ) string {
253
298
return fmt .Sprintf (`
254
299
resource "vercel_project" "test" {
@@ -401,3 +446,22 @@ resource "vercel_deployment" "bitbucket" {
401
446
}
402
447
` , projectSuffix , testGithubRepo (), testBitbucketRepo (), teamID )
403
448
}
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