diff --git a/__tests__/__system__/cli/upload/file-to-data-set/cli.upload.file-to-data-set.test.ts b/__tests__/__system__/cli/upload/file-to-data-set/cli.upload.file-to-data-set.test.ts index 0ec1b78a..9886e943 100644 --- a/__tests__/__system__/cli/upload/file-to-data-set/cli.upload.file-to-data-set.test.ts +++ b/__tests__/__system__/cli/upload/file-to-data-set/cli.upload.file-to-data-set.test.ts @@ -59,28 +59,6 @@ describe("upload file to data set command", () => { await connection.deleteDataset(destination); // delete the temporary member }); - it("should be able to upload a file with // to a data set and verify that the data set exists and contains the right content", async () => { - // This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533 - // FTP client checks whether the string to put is a local file path first. - // If yes, it puts the whole file; otherwise, it puts the string as the contents. - // On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//". - const fileToUpload = __dirname + "/resources/file2.txt"; - const memberSuffixLength = 6; - const destination = testDataSet + "(R" + generateRandomAlphaNumericString(memberSuffixLength) + ")"; - const result = runCliScript(__dirname + "/__scripts__/command_upload_file_to_data_set.sh", testEnvironment, - [fileToUpload, destination]); - expect(result.stderr.toString()).toEqual(""); - expect(result.status).toEqual(0); - const uploadedContent = (await connection.getDataset(destination)).toString(); - const expectedContent = IO.readFileSync(fileToUpload).toString(); - const uploadedLines = uploadedContent.split(/\r?\n/g); - const expectedLines = expectedContent.split(/\r?\n/g); - for (let x = 0; x < expectedLines.length; x++) { - expect(uploadedLines[x].trim()).toEqual(expectedLines[x].trim()); - } - await connection.deleteDataset(destination); // delete the temporary member - }); - it("should be able to upload a file to a data set in binary mode and verify that the content is correct", async () => { const fileToUpload = testEnvironment.workingDir + "/binary.bin"; const randomContentLength = 60; diff --git a/__tests__/__system__/cli/upload/file-to-data-set/resources/file2.txt b/__tests__/__system__/cli/upload/file-to-data-set/resources/file2.txt deleted file mode 100644 index 295fb6ba..00000000 --- a/__tests__/__system__/cli/upload/file-to-data-set/resources/file2.txt +++ /dev/null @@ -1 +0,0 @@ -//abc \ No newline at end of file diff --git a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts index 032ec87d..6e9426ef 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts @@ -13,7 +13,7 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToDataSetHandler from "../../../../../src/cli/upload/stdin-to-data-set/StdinToDataSet.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload file to data set handler", () => { +describe("Upload stdio to data set handler", () => { it("should return no data set if the data set is not found.", async () => { const handler = new UploadStdinToDataSetHandler(); @@ -37,4 +37,31 @@ describe("Upload file to data set handler", () => { expect(mockResponse.console.log.mock.calls[0][2]).toBe("DS1"); }); + it("should upload contents with Buffer.", async () => { + // This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533 + // FTP client checks whether the string to put is a local file path first. + // If yes, it puts the whole file; otherwise, it puts the string as the contents. + // On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//". + + const handler = new UploadStdinToDataSetHandler(); + + CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss"))); + CoreUtils.addCarriageReturns = jest.fn().mockReturnValue(("sss")); + const mockResponse = TestUtils.getMockResponse(); + const mockUploadDataset = jest.fn(); + const mockParams: any = { + arguments: { + dataSet: "ds1" + }, + connection: { + uploadDataset: mockUploadDataset + }, + response: mockResponse + }; + await handler.processFTP(mockParams); + // The contents to upload must be Buffer. FTP client tries to fs.stat() first, + // if the contents is string. + expect(mockUploadDataset.mock.calls[0][0] instanceof Buffer).toBeTruthy(); + }); + });