@@ -14,23 +14,24 @@ const TOKEN = 'test'
14
14
15
15
test . beforeEach ( async ( t ) => {
16
16
const port = await getPort ( )
17
- t . context . blobRequestCount = { set : 0 , get : 0 }
17
+ t . context . blobRequests = { }
18
18
19
19
const tmpDir = await tmp . dir ( )
20
20
t . context . blobServer = new BlobsServer ( {
21
21
port,
22
22
token : TOKEN ,
23
23
directory : tmpDir . path ,
24
- onRequest : ( { type } ) => {
25
- t . context . blobRequestCount [ type ] = ( t . context . blobRequestCount [ type ] || 0 ) + 1
24
+ onRequest : ( { type, url } ) => {
25
+ t . context . blobRequests [ type ] = t . context . blobRequests [ type ] || [ ]
26
+ t . context . blobRequests [ type ] . push ( url )
26
27
} ,
27
28
} )
28
29
29
30
await t . context . blobServer . start ( )
30
31
31
32
process . env . NETLIFY_BLOBS_CONTEXT = Buffer . from (
32
33
JSON . stringify ( {
33
- edgeURL : `http://localhost:${ port } ` ,
34
+ apiURL : `http://localhost:${ port } ` ,
34
35
} ) ,
35
36
) . toString ( 'base64' )
36
37
} )
@@ -50,27 +51,74 @@ test.serial("blobs upload, don't run when deploy id is provided and no files in
50
51
. runBuildProgrammatic ( )
51
52
52
53
t . true ( success )
53
- t . is ( t . context . blobRequestCount . set , 0 )
54
+ t . is ( t . context . blobRequests . set , undefined )
54
55
55
56
t . false ( stdout . join ( '\n' ) . includes ( 'Uploading blobs to deploy store' ) )
56
57
} )
57
58
58
- test . serial ( "blobs upload, don't run when there are files but deploy id is not provided" , async ( t ) => {
59
- const fixture = await new Fixture ( './fixtures/src_with_blobs' ) . withCopyRoot ( { git : false } )
59
+ test . serial (
60
+ "blobs upload, don't run when there are files but deploy id is not provided using legacy API" ,
61
+ async ( t ) => {
62
+ const fixture = await new Fixture ( './fixtures/src_with_blobs_legacy' ) . withCopyRoot ( { git : false } )
63
+
64
+ const {
65
+ success,
66
+ logs : { stdout } ,
67
+ } = await fixture . withFlags ( { token : TOKEN , offline : true , cwd : fixture . repositoryRoot } ) . runBuildProgrammatic ( )
68
+
69
+ t . true ( success )
70
+
71
+ const blobsDir = join ( fixture . repositoryRoot , '.netlify' , 'blobs' , 'deploy' )
72
+ await t . notThrowsAsync ( access ( blobsDir ) )
73
+
74
+ t . is ( t . context . blobRequests . set , undefined )
75
+
76
+ t . false ( stdout . join ( '\n' ) . includes ( 'Uploading blobs to deploy store' ) )
77
+ } ,
78
+ )
79
+
80
+ test . serial ( 'blobs upload, uploads files to deploy store using legacy API' , async ( t ) => {
81
+ const fixture = await new Fixture ( './fixtures/src_with_blobs_legacy' ) . withCopyRoot ( { git : false } )
60
82
61
83
const {
62
84
success,
63
85
logs : { stdout } ,
64
- } = await fixture . withFlags ( { token : TOKEN , offline : true , cwd : fixture . repositoryRoot } ) . runBuildProgrammatic ( )
86
+ } = await fixture
87
+ . withFlags ( { deployId : 'abc123' , siteId : 'test' , token : TOKEN , offline : true , cwd : fixture . repositoryRoot } )
88
+ . runBuildProgrammatic ( )
65
89
66
90
t . true ( success )
91
+ t . is ( t . context . blobRequests . set . length , 6 )
67
92
68
- const blobsDir = join ( fixture . repositoryRoot , '.netlify' , 'blobs' , 'deploy' )
69
- await t . notThrowsAsync ( access ( blobsDir ) )
93
+ const regionRequests = t . context . blobRequests . set . filter ( ( urlPath ) => {
94
+ const url = new URL ( urlPath , 'http://localhost' )
70
95
71
- t . is ( t . context . blobRequestCount . set , 0 )
96
+ return url . searchParams . has ( 'region' )
97
+ } )
72
98
73
- t . false ( stdout . join ( '\n' ) . includes ( 'Uploading blobs to deploy store' ) )
99
+ t . is ( regionRequests . length , 0 )
100
+
101
+ const storeOpts = { deployID : 'abc123' , siteID : 'test' , token : TOKEN }
102
+ if ( semver . lt ( nodeVersion , '18.0.0' ) ) {
103
+ const nodeFetch = await import ( 'node-fetch' )
104
+ storeOpts . fetch = nodeFetch . default
105
+ }
106
+
107
+ const store = getDeployStore ( storeOpts )
108
+
109
+ const blob1 = await store . getWithMetadata ( 'something.txt' )
110
+ t . is ( blob1 . data , 'some value' )
111
+ t . deepEqual ( blob1 . metadata , { } )
112
+
113
+ const blob2 = await store . getWithMetadata ( 'with-metadata.txt' )
114
+ t . is ( blob2 . data , 'another value' )
115
+ t . deepEqual ( blob2 . metadata , { meta : 'data' , number : 1234 } )
116
+
117
+ const blob3 = await store . getWithMetadata ( 'nested/file.txt' )
118
+ t . is ( blob3 . data , 'file value' )
119
+ t . deepEqual ( blob3 . metadata , { some : 'metadata' } )
120
+
121
+ t . true ( stdout . join ( '\n' ) . includes ( 'Uploading blobs to deploy store' ) )
74
122
} )
75
123
76
124
test . serial ( 'blobs upload, uploads files to deploy store' , async ( t ) => {
@@ -84,7 +132,17 @@ test.serial('blobs upload, uploads files to deploy store', async (t) => {
84
132
. runBuildProgrammatic ( )
85
133
86
134
t . true ( success )
87
- t . is ( t . context . blobRequestCount . set , 3 )
135
+
136
+ // 3 requests for getting pre-signed URLs + 3 requests for hitting them.
137
+ t . is ( t . context . blobRequests . set . length , 6 )
138
+
139
+ const regionAutoRequests = t . context . blobRequests . set . filter ( ( urlPath ) => {
140
+ const url = new URL ( urlPath , 'http://localhost' )
141
+
142
+ return url . searchParams . get ( 'region' ) === 'auto'
143
+ } )
144
+
145
+ t . is ( regionAutoRequests . length , 3 )
88
146
89
147
const storeOpts = { deployID : 'abc123' , siteID : 'test' , token : TOKEN }
90
148
if ( semver . lt ( nodeVersion , '18.0.0' ) ) {
@@ -118,7 +176,7 @@ test.serial('blobs upload, cancels deploy if blob metadata is malformed', async
118
176
const blobsDir = join ( fixture . repositoryRoot , '.netlify' , 'blobs' , 'deploy' )
119
177
await t . notThrowsAsync ( access ( blobsDir ) )
120
178
121
- t . is ( t . context . blobRequestCount . set , 0 )
179
+ t . is ( t . context . blobRequests . set , undefined )
122
180
123
181
t . false ( success )
124
182
t . is ( severityCode , 4 )
@@ -136,7 +194,7 @@ if (semver.gte(nodeVersion, '16.9.0')) {
136
194
. runBuildProgrammatic ( )
137
195
138
196
t . true ( success )
139
- t . is ( t . context . blobRequestCount . set , 3 )
197
+ t . is ( t . context . blobRequests . set . length , 6 )
140
198
141
199
const storeOpts = { deployID : 'abc123' , siteID : 'test' , token : TOKEN }
142
200
if ( semver . lt ( nodeVersion , '18.0.0' ) ) {
0 commit comments