Skip to content

Commit

Permalink
Merge pull request #152 from zowe/upload-text-dataset-wuth-buffer
Browse files Browse the repository at this point in the history
Upload dataset using Buffer
  • Loading branch information
zFernand0 authored Feb 9, 2024
2 parents 9497b0f + 5435aea commit 99f428d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the z/OS FTP Plug-in for Zowe CLI will be documented in t

## Recent Changes

- BugFix: Upload dataset using Buffer, stead of string. [2533](https://github.com/zowe/vscode-extension-for-zowe/issues/2533)
- Simplify the preparation for JCL system tests


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 stdin to data set handler", () => {

it("should return no data set if the data set is not found.", async () => {
const handler = new UploadStdinToDataSetHandler();
Expand All @@ -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();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils";
import UploadStdinToUssFileHandler from "../../../../../src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler";
import TestUtils from "../../TestUtils";

describe("Upload file to data set handler", () => {
describe("Upload stdin to USS file handler", () => {

it("should return no data set if the data set is not found.", async () => {
it("should return no data set if the USS file is not found.", async () => {
const handler = new UploadStdinToUssFileHandler();

CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss")));
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zowe/zos-ftp-for-zowe-cli",
"version": "2.1.7",
"version": "2.1.8",
"author": "Zowe",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/api/DataSetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class DataSetUtils {
this.log.debug("Attempting to upload to data set '%s' in transfer mode '%s'", dsn, option.transferType);
}
if (transferType === TRANSFER_TYPE_ASCII) {
content = CoreUtils.addCarriageReturns(content.toString());
content = Buffer.from(CoreUtils.addCarriageReturns(content.toString()));
}
await connection.uploadDataset(content, "'" + dsn + "'", transferType, siteparm);
}
Expand Down

0 comments on commit 99f428d

Please sign in to comment.