Skip to content

Commit

Permalink
Merge pull request #2882 from zowe/fix/support-binary-ds
Browse files Browse the repository at this point in the history
fix(ds): Support opening data sets in binary mode
  • Loading branch information
JillieBeanSim authored May 3, 2024
2 parents 2718b78 + 213e75a commit 575a6e3
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 162 deletions.
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### Bug fixes

- Fixed issue where data sets or members containing binary content cannot be opened. [#2696](https://github.com/zowe/zowe-explorer-vscode/issues/2696)

## `2.15.4`

### New features and enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function createGlobalMocks() {
statusBarMsgSpy: null,
mvsApi: null,
mockShowWarningMessage: jest.fn(),
mockTextDocuments: [],
concatChildNodes: jest.spyOn(sharedUtils, "concatChildNodes"),
};

Expand Down Expand Up @@ -100,6 +101,7 @@ function createGlobalMocks() {
Object.defineProperty(vscode.workspace, "openTextDocument", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.workspace, "getConfiguration", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "showTextDocument", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.workspace, "textDocuments", { value: newMocks.mockTextDocuments, configurable: true });
Object.defineProperty(vscode.window, "showQuickPick", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createQuickPick", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.commands, "executeCommand", { value: jest.fn(), configurable: true });
Expand Down Expand Up @@ -267,15 +269,16 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {

it("Checking common PS dataset refresh", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const node = new ZoweDatasetNode({
label: "HLQ.TEST.AFILE7",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
const documentFilePath = path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString());

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockResolvedValueOnce({
success: true,
commandResponse: null,
Expand All @@ -290,27 +293,26 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
blockMocks.zosmfSession,
node.label,
expect.objectContaining({
file: path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString()),
file: documentFilePath,
returnEtag: true,
})
);
expect(mocked(vscode.workspace.openTextDocument)).toBeCalledWith(
path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString())
);
expect(mocked(vscode.workspace.openTextDocument)).toBeCalledWith(documentFilePath);
expect(mocked(vscode.window.showTextDocument)).toBeCalledTimes(2);
expect(mocked(vscode.commands.executeCommand)).toBeCalledWith("workbench.action.closeActiveEditor");
});
it("Checking duplicate PS dataset refresh attempt", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const node = new ZoweDatasetNode({
label: "HLQ.TEST.AFILE7",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
const documentFilePath = path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString());

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: false } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: false } as any);
mocked(zowe.Download.dataSet).mockResolvedValueOnce({
success: true,
commandResponse: null,
Expand All @@ -332,8 +334,9 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
const documentFilePath = path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString());

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockRejectedValueOnce(Error("not found"));

globalMocks.getContentsSpy.mockRejectedValueOnce(new Error("not found"));
Expand All @@ -345,16 +348,17 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
});
it("Checking failed attempt to refresh PDS Member", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const parent = new ZoweDatasetNode({
label: "parent",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: blockMocks.datasetSessionNode,
});
const child = new ZoweDatasetNode({ label: "child", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: parent });
const documentFilePath = path.join(globals.DS_DIR, child.getSessionNode().label.toString(), child.label.toString());

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockRejectedValueOnce(Error(""));

await dsActions.refreshPS(child);
Expand All @@ -371,16 +375,17 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
});
it("Checking favorite empty PDS refresh", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const node = new ZoweDatasetNode({
label: "HLQ.TEST.AFILE7",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: blockMocks.datasetSessionNode,
});
const documentFilePath = path.join(globals.DS_DIR, node.getSessionNode().label.toString(), node.label.toString());
node.contextValue = globals.DS_PDS_CONTEXT + globals.FAV_SUFFIX;

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockResolvedValueOnce({
success: true,
commandResponse: null,
Expand All @@ -396,17 +401,22 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
});
it("Checking favorite PDS Member refresh", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const parent = new ZoweDatasetNode({
label: "parent",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: blockMocks.datasetSessionNode,
});
const child = new ZoweDatasetNode({ label: "child", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: parent });
const documentFilePath = path.join(
globals.DS_DIR,
child.getSessionNode().label.toString(),
parent.label.toString() + "(" + child.label.toString() + ")"
);
parent.contextValue = globals.DS_PDS_CONTEXT + globals.FAV_SUFFIX;

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockResolvedValueOnce({
success: true,
commandResponse: null,
Expand All @@ -422,17 +432,18 @@ describe("Dataset Actions Unit Tests - Function refreshPS", () => {
});
it("Checking favorite PS refresh", async () => {
globals.defineGlobals("");
createGlobalMocks();
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocksShared();
const parent = new ZoweDatasetNode({
label: "parent",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: blockMocks.datasetSessionNode,
});
const child = new ZoweDatasetNode({ label: "child", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: parent });
const documentFilePath = path.join(globals.DS_DIR, child.getSessionNode().label.toString(), child.label.toString());
child.contextValue = globals.DS_FAV_CONTEXT;

mocked(vscode.workspace.openTextDocument).mockResolvedValueOnce({ isDirty: true } as any);
globalMocks.mockTextDocuments.push({ fileName: documentFilePath, isDirty: true } as any);
mocked(zowe.Download.dataSet).mockResolvedValueOnce({
success: true,
commandResponse: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe("Test src/dataset/extension", () => {
},
{
name: "zowe.ds.openWithEncoding",
mock: [{ spy: jest.spyOn(dsProvider, "openWithEncoding"), arg: [test.value] }],
mock: [{ spy: jest.spyOn(dsProvider, "openWithEncoding"), arg: [test.value, undefined] }],
},
{
name: "onDidChangeConfiguration",
Expand Down
Loading

0 comments on commit 575a6e3

Please sign in to comment.