Skip to content

Commit

Permalink
resolve FTP getContents bug for MVS and USS (#3200)
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
Co-authored-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com>
  • Loading branch information
traeok and zFernand0 authored Oct 8, 2024
1 parent 37a5102 commit f1b2471
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/zowe-explorer-ftp-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the "zowe-explorer-ftp-extension" extension will be docum

### Bug fixes

- Fixed bug where the `getContents` MVS and USS APIs failed to return whenever a local file path was provided. [#3199](https://github.com/zowe/zowe-explorer-vscode/issues/3199)

## `3.0.0`

### New features and enhancements
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-ftp-extension/__mocks__/mockUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Idea is borrowed from: https://github.com/kulshekhar/ts-jest/blob/master/src/util/testing.ts
export const mocked = <T extends (..._args: any[]) => any>(fn: T): jest.Mock<ReturnType<T>> => fn as any;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as tmp from "tmp";
import { Gui, imperative } from "@zowe/zowe-explorer-api";
import * as globals from "../../../src/globals";
import { ZoweFtpExtensionError } from "../../../src/ZoweFtpExtensionError";
import { mocked } from "../../../__mocks__/mockUtils";

// two methods to mock modules: create a __mocks__ file for zowe-explorer-api.ts and direct mock for extension.ts
jest.mock("../../../__mocks__/@zowe/zowe-explorer-api.ts");
Expand Down Expand Up @@ -93,6 +94,7 @@ describe("FtpMvsApi", () => {

expect(result.apiResponse.etag).toHaveLength(64);
expect(DataSetUtils.downloadDataSet).toHaveBeenCalledTimes(1);
expect(mocked(DataSetUtils.downloadDataSet).mock.calls[0][2].localFile).toBe(localFile);
expect(MvsApi.releaseConnection).toHaveBeenCalled();

expect((response._readableState.buffer.head?.data ?? response._readableState.buffer).toString()).toContain("Hello world");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as globals from "../../../src/globals";
import { ZoweFtpExtensionError } from "../../../src/ZoweFtpExtensionError";
import * as tmp from "tmp";
import { imperative } from "@zowe/zowe-explorer-api";
import { mocked } from "../../../__mocks__/mockUtils";

// two methods to mock modules: create a __mocks__ file for zowe-explorer-api.ts and direct mock for extension.ts
jest.mock("../../../__mocks__/@zowe/zowe-explorer-api.ts");
Expand Down Expand Up @@ -78,6 +79,7 @@ describe("FtpUssApi", () => {

expect(result.apiResponse.etag).toHaveLength(64);
expect(UssUtils.downloadFile).toHaveBeenCalledTimes(1);
expect(mocked(UssUtils.downloadFile).mock.calls[0][2].localFile).toBe(localFile);
expect(UssApi.releaseConnection).toHaveBeenCalled();

expect((response._readableState.buffer.head?.data ?? response._readableState.buffer).toString()).toContain("Hello world");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class FtpMvsApi extends AbstractFtpApi implements MainframeInteraction.IM
const result = this.getDefaultResponse();
const transferOptions = {
encoding: options.encoding,
localFile: undefined,
localFile: options.file,
transferType: CoreUtils.getBinaryTransferModeOrDefault(options.binary),
};
const fileOrStreamSpecified = options.file != null || options.stream != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class FtpUssApi extends AbstractFtpApi implements MainframeInteraction.IU
const result = this.getDefaultResponse();
const transferOptions = {
transferType: CoreUtils.getBinaryTransferModeOrDefault(options.binary),
localFile: undefined,
localFile: options.file,
size: 1,
};
const fileOrStreamSpecified = options.file != null || options.stream != null;
Expand Down

0 comments on commit f1b2471

Please sign in to comment.