@samitouri / QOSami-HFS / commits / 8ff50e52

test: check final size of successful uploads

Massimo Melina committed Jan 24, 2025 at 19:02 UTC 8ff50e52ddb5848f4804586d86d1c43cb33eb06f
1 file changed +15 -1
tests/test.ts
+15 -1
@@ -206,9 +206,23 @@ function login(usr: string, pwd=password) {
206
207 function reqUpload(dest: string, tester: Tester, body?: string | Readable, size?: number) {
208 const fn = join(__dirname, 'page/gpl.png')
209 + size ??= (body as any)?.length ?? statSync(fn).size // it's ok that Readable.length is undefined
210 + if (tester === 200)
211 + tester = {
212 + status: tester,
213 + cb(data) {
214 + const fn = ROOT + decodeURI(data.uri).replace(UPLOAD_ROOT, '')
215 + const stats = try_(() => statSync(fn))
216 + if (!stats)
217 + throw Error("uploaded file not found: " + fn)
218 + if (size !== stats.size)
219 + throw Error("uploaded file wrong size: " + fn)
220 + return true
221 + }
222 + }
223 return req(dest, tester, {
224 method: 'PUT',
211 - headers: { 'content-length': size ?? (body as any)?.length ?? statSync(fn).size }, // it's ok that Readable.length is undefined
225 + headers: { 'content-length': size },
226 body: body ?? createReadStream(fn)
227 })
228 }