UNPKG

@itwin/object-storage-tests-backend

Version:

Tests for generic storage packages

58 lines 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testDownloadToStreamWithConfig = exports.testDownloadToBufferWithConfig = exports.testDownloadFromUrlToStream = exports.testDownloadFromUrlToBuffer = void 0; const Config_1 = require("../Config"); const Global_test_1 = require("../Global.test"); const utils_1 = require("../utils"); const { serverStorage } = Config_1.config; async function testDownloadFromUrlToBuffer(storageUnderTest) { const contentBuffer = Buffer.from("test-download-from-url-to-buffer"); const testDirectory = await Global_test_1.testDirectoryManager.createNew(); const uploadedFile = await testDirectory.uploadFile({ objectName: "file-to-download-from-url.txt" }, contentBuffer, undefined); const downloadUrl = await serverStorage.getDownloadUrl(uploadedFile); const response = await storageUnderTest.download({ url: downloadUrl, transferType: "buffer", }); utils_1.assertBuffer(response, contentBuffer); } exports.testDownloadFromUrlToBuffer = testDownloadFromUrlToBuffer; async function testDownloadFromUrlToStream(storageUnderTest) { const contentBuffer = Buffer.from("test-download-from-url-to-stream"); const testDirectory = await Global_test_1.testDirectoryManager.createNew(); const uploadedFile = await testDirectory.uploadFile({ objectName: "file-to-download-from-url.txt" }, contentBuffer, undefined); const downloadUrl = await serverStorage.getDownloadUrl(uploadedFile); const response = await storageUnderTest.download({ url: downloadUrl, transferType: "stream", }); await utils_1.assertStream(response, contentBuffer); } exports.testDownloadFromUrlToStream = testDownloadFromUrlToStream; async function testDownloadToBufferWithConfig(storageUnderTest) { const contentBuffer = Buffer.from("test-download-to-buffer-with-config"); const testDirectory = await Global_test_1.testDirectoryManager.createNew(); const uploadedFile = await testDirectory.uploadFile({ objectName: "file-to-download-with-config.txt" }, contentBuffer, undefined); const downloadConfig = await serverStorage.getDownloadConfig(testDirectory.baseDirectory); const response = await storageUnderTest.download({ reference: uploadedFile, transferConfig: downloadConfig, transferType: "buffer", }); utils_1.assertBuffer(response, contentBuffer); } exports.testDownloadToBufferWithConfig = testDownloadToBufferWithConfig; async function testDownloadToStreamWithConfig(storageUnderTest) { const contentBuffer = Buffer.from("test-download-to-stream-with-config"); const testDirectory = await Global_test_1.testDirectoryManager.createNew(); const uploadedFile = await testDirectory.uploadFile({ objectName: "file-to-download-with-config.txt" }, contentBuffer, undefined); const downloadConfig = await serverStorage.getDownloadConfig(testDirectory.baseDirectory); const response = await storageUnderTest.download({ reference: uploadedFile, transferConfig: downloadConfig, transferType: "stream", }); await utils_1.assertStream(response, contentBuffer); } exports.testDownloadToStreamWithConfig = testDownloadToStreamWithConfig; //# sourceMappingURL=DownloadTests.js.map