diff --git a/ENCO#EDJR897694.ZOSFILE.DOWNLOAD.A73312.ENCO#ED b/ENCO#EDJR897694.ZOSFILE.DOWNLOAD.A73312.ENCO#ED new file mode 100644 index 0000000000..74b08ecfd8 --- /dev/null +++ b/ENCO#EDJR897694.ZOSFILE.DOWNLOAD.A73312.ENCO#ED @@ -0,0 +1 @@ +$)$)$) \ No newline at end of file diff --git a/JR897694.ZOSFILE.DOWNLOAD.A1562310.A442242 b/JR897694.ZOSFILE.DOWNLOAD.A1562310.A442242 new file mode 100644 index 0000000000..74b08ecfd8 --- /dev/null +++ b/JR897694.ZOSFILE.DOWNLOAD.A1562310.A442242 @@ -0,0 +1 @@ +$)$)$) \ No newline at end of file diff --git a/JR897694.ZOSFILE.DOWNLOAD.A2353578.A5866 b/JR897694.ZOSFILE.DOWNLOAD.A2353578.A5866 new file mode 100644 index 0000000000..74b08ecfd8 --- /dev/null +++ b/JR897694.ZOSFILE.DOWNLOAD.A2353578.A5866 @@ -0,0 +1 @@ +$)$)$) \ No newline at end of file diff --git a/JR897694.ZOSFILE.DOWNLOAD.A6003736.A78861 b/JR897694.ZOSFILE.DOWNLOAD.A6003736.A78861 new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/JR897694.ZOSFILE.DOWNLOAD.A6003736.A78861 @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/JR897694.ZOSFILE.DOWNLOAD.A8747183.A70397 b/JR897694.ZOSFILE.DOWNLOAD.A8747183.A70397 new file mode 100644 index 0000000000..74b08ecfd8 --- /dev/null +++ b/JR897694.ZOSFILE.DOWNLOAD.A8747183.A70397 @@ -0,0 +1 @@ +$)$)$) \ No newline at end of file diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes index 3134e437c5..b5698f48e5 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes +++ b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes @@ -2,4 +2,4 @@ *.bin binary binary *.jcl IBM-1047 IBM-1047 *.md UTF-8 UTF-8 -*.txt UTF-8 IBM-1147 +*.txt binary binary diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index ecddd8231e..99ba8e18ae 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -24,7 +24,8 @@ import { IMountFsOptions, Mount, Unmount, - IUSSListOptions + IUSSListOptions, + ZosFilesAttributes } from "../../../../src"; import { Imperative, IO, Session } from "@zowe/imperative"; import { inspect } from "util"; @@ -37,10 +38,12 @@ import { posix } from "path"; import { Shell } from "@zowe/zos-uss-for-zowe-sdk"; import { PassThrough } from "stream"; import { text } from "stream/consumers"; +import { runCliScript } from "../../../../../../__tests__/__packages__/cli-test-utils/lib"; const rimraf = require("rimraf").sync; const delayTime = 2000; const testData = "abcdefghijklmnopqrstuvwxyz"; +const testDataBinary = "[][][]"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -1018,7 +1021,7 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea let error; let response: IZosFilesResponse; - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testDataBinary)); await wait(delayTime); try { @@ -1081,6 +1084,61 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea }); + it("should download uss file with --attributes flag", async () => { + let error; + let response: any; + let downloadResponse: any; + let zosAttributes = Object.create(ZosFilesAttributes.prototype); + zosAttributes.attributes = new Map([ + ['*.json', { ignore: true }], + ['*.bin', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }], + ['*.jcl', { ignore: false, localEncoding: 'IBM-1047', remoteEncoding: 'IBM-1047' }], + ['*.md', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'UTF-8' }], + ['*.txt', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'IBM-1047' }] + ]); + try { + response = await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testDataBinary)); + downloadResponse = await Download.ussFile(REAL_SESSION, ussname, { attributes: zosAttributes}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(downloadResponse).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testDataBinary); + }); + + it("should download uss file with --attributes flag - binary", async () => { + let error; + let response: any; + let downloadResponse: any; + let zosAttributes = Object.create(ZosFilesAttributes.prototype); + zosAttributes.attributes = new Map([ + ['*.json', { ignore: true }], + ['*.bin', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }], + ['*.jcl', { ignore: false, localEncoding: 'IBM-1047', remoteEncoding: 'IBM-1047' }], + ['*.md', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'UTF-8' }], + ['*.txt', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }] + ]); + try { + response = await Upload.uploadFile(REAL_SESSION, __dirname+"/__resources__/testfiles/downloadEncodingCheck.txt" ,ussname, { attributes: zosAttributes}); + downloadResponse = await Download.ussFile(REAL_SESSION, ussname, { attributes: zosAttributes}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(downloadResponse).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + + expect(fileContents).toEqual(fs.readFileSync(__dirname+"/__resources__/testfiles/downloadEncodingCheck.txt").toString()); + }); + // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional it("should download a 10mb uss file and return Etag", async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes new file mode 100644 index 0000000000..88a1b0f51f --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes @@ -0,0 +1,5 @@ +*.json - +*.bin binary binary +*.jcl IBM-1047 IBM-1047 +*.md UTF-8 UTF-8 +*.txt UTF-8 IBM-1047 \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes-binary b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes-binary new file mode 100644 index 0000000000..0f79a06bc2 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/.zosattributes-binary @@ -0,0 +1,5 @@ +*.json - +*.bin binary binary +*.jcl IBM-1047 IBM-1047 +*.md UTF-8 UTF-8 +*.txt binary binary \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/download/__resources__/download_file.sh b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/download_file.sh new file mode 100755 index 0000000000..b1e59dd8c3 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/download_file.sh @@ -0,0 +1,12 @@ +#!/bin/bash +account=$1 +host=$2 +port=$3 +user=$4 +password=$5 +ru=$6 +fileToDownload=$7 +attributes=$8 + +zowe zos-files download uss $fileToDownload --attributes $attributes --host $host --port $port --user $user --password $password --ru $ru +exit $? \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/download/__resources__/testfiles/downloadEncodingCheck.txt b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/testfiles/downloadEncodingCheck.txt new file mode 100644 index 0000000000..385781092d --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/testfiles/downloadEncodingCheck.txt @@ -0,0 +1 @@ +[][][] \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/download/__resources__/upload_file_to_uss.sh b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/upload_file_to_uss.sh new file mode 100755 index 0000000000..5531b63422 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/download/__resources__/upload_file_to_uss.sh @@ -0,0 +1,13 @@ +#!/bin/bash +account=$1 +host=$2 +port=$3 +user=$4 +password=$5 +ru=$6 +inputFile=$7 +ussName=$8 +encoding=$9 + +zowe zos-files upload file-to-uss $inputFile $ussName --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru +exit $? \ No newline at end of file diff --git a/usstest.txt b/usstest.txt deleted file mode 100644 index 3fa13c68bf..0000000000 --- a/usstest.txt +++ /dev/null @@ -1 +0,0 @@ -á { í ó ú ñ Ç ß 12345 |à£$% ^ ° § $ # ¤ \ No newline at end of file