Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content for api response on upload SDK methods #2381

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi

## Recent Changes

- BugFix: Corrected the `apiResponse` response value from `streamToDataSet()`,`streamToUss()`,`bufferToUss()` and `bufferToDataSet()` on the Upload SDK. [#2381](https://github.com/zowe/zowe-cli/pull/2381)
- BugFix: Corrected the `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378)

## `8.9.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { deleteFiles, getUniqueDatasetName, stripNewLines, wait, waitTime } from
import * as fs from "fs";
import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment";
import { runCliScript } from "../../../../../../__tests__/__packages__/cli-test-utils/src";
import { Readable } from "stream";

let REAL_SESSION: Session;
let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
Expand Down Expand Up @@ -309,6 +310,49 @@ describe("Upload Data Set", () => {
}
});

it("should upload a PDS file - bufferToDataSet()", async () => {
let error;
let uploadResponse;
let getResponse;
const data: Buffer = Buffer.from(testdata);

try {
uploadResponse = await Upload.bufferToDataSet(REAL_SESSION, data, dsname+"(TEST)");
getResponse = await Get.dataSet(REAL_SESSION, dsname+"(TEST)");
} catch (err) {
error = err;
Imperative.console.info("Error: " + inspect(error));
}

expect(error).toBeFalsy();

expect(uploadResponse.apiResponse).toMatchObject({"success": true, "from": "Buffer<>","to": dsname+"(TEST)"});
expect(Buffer.from(getResponse.toString().trim())).toEqual(data);
});

it("should upload a PDS file - streamToDataSet()", async () => {
let error;
let uploadResponse;
let getResponse;

const inputStream = new Readable();
inputStream.push(testdata);
inputStream.push(null);

try {
uploadResponse = await Upload.streamToDataSet(REAL_SESSION, inputStream, dsname+"(TEST)");
getResponse = await Get.dataSet(REAL_SESSION, dsname+"(TEST)");
} catch (err) {
error = err;
Imperative.console.info("Error: " + inspect(error));
}

expect(error).toBeFalsy();

expect(uploadResponse.apiResponse).toMatchObject({"success": true, "from": "Stream<>","to": dsname+"(TEST)"});
expect(getResponse.toString().trim()).toEqual(testdata);
});

it("should upload a file to a partitioned data set member using full path", async () => {
let error;
let response: IZosFilesResponse;
Expand Down Expand Up @@ -733,7 +777,7 @@ describe("Upload USS file", () => {
await deleteFiles(REAL_SESSION, ussname);
});

it("should upload a USS file", async () => {
it("should upload a USS file - bufferToUssFile()", async () => {
let error;
let uploadResponse;
let getResponse;
Expand All @@ -748,9 +792,33 @@ describe("Upload USS file", () => {
}

expect(error).toBeFalsy();

expect(uploadResponse.apiResponse).toMatchObject({"success": true, "from": "Buffer<>","to": ussname});
expect(getResponse).toEqual(Buffer.from(data.toString()));
});

it("should upload a USS file - streamToUssFile()", async () => {
let error;
let uploadResponse;
let getResponse;
const inputStream = new Readable();
inputStream.push(testdata);
inputStream.push(null);

try {
uploadResponse = await Upload.streamToUssFile(REAL_SESSION, ussname, inputStream);
getResponse = await Get.USSFile(REAL_SESSION, ussname);
} catch (err) {
error = err;
Imperative.console.info("Error: " + inspect(error));
}

expect(error).toBeFalsy();

expect(uploadResponse.apiResponse).toMatchObject({"success": true, "from": "Stream<>","to": ussname});
expect(getResponse).toEqual(Buffer.from(testdata));
});

it("should upload a USS file in binary mode", async () => {
let error;
let uploadResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(response).toBeDefined();
expect(response.apiResponse).toMatchObject({"from": "Buffer<>", "success": true, "to": dsName});

expect(zosmfPutFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfPutFullSpy).toHaveBeenCalledWith(dummySession, {resource: endpoint,
Expand Down Expand Up @@ -748,6 +749,7 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(response).toBeDefined();
expect(response.apiResponse).toMatchObject({"from": "Stream<>", "success": true, "to": dsName});

expect(zosmfPutFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfPutFullSpy).toHaveBeenCalledWith(dummySession, {resource: endpoint,
Expand Down Expand Up @@ -1755,6 +1757,7 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(USSresponse).toBeDefined();
expect(USSresponse.apiResponse).toMatchObject({"from": "Buffer<>", "success": true, "to": dsName});

const normalizedData = ZosFilesUtils.normalizeNewline(data);
expect(data.length).not.toBe(normalizedData.length);
Expand Down Expand Up @@ -1830,6 +1833,7 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(USSresponse).toBeDefined();
expect(USSresponse.apiResponse).toMatchObject({"from": "Stream<>", "success": true, "to": dsName});
expect(USSresponse.success).toBeTruthy();

expect(zosmfExpectFullSpy).toHaveBeenCalledTimes(1);
Expand Down
25 changes: 21 additions & 4 deletions packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ export class Upload {
const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions);

// By default, apiResponse is empty when uploading
const apiResponse: any = {};
const apiResponse: any = {
success: true,
from: "Buffer<>",
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
to: dataSetName
};

// Return Etag in apiResponse, if requested
if (options.returnEtag) {
Expand Down Expand Up @@ -242,7 +246,11 @@ export class Upload {
const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions);

// By default, apiResponse is empty when uploading
const apiResponse: any = {};
const apiResponse: any = {
success: true,
from: "Stream<>",
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
to: dataSetName
};

// Return Etag in apiResponse, if requested
if (options.returnEtag) {
Expand Down Expand Up @@ -481,7 +489,12 @@ export class Upload {
const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions);

// By default, apiResponse is empty when uploading
const apiResponse: any = {};
const apiResponse: any =
{
success: true,
from: "Buffer<>",
to: origUssname
};

// Return Etag in apiResponse, if requested
if (options.returnEtag) {
Expand Down Expand Up @@ -541,7 +554,11 @@ export class Upload {
}

// By default, apiResponse is empty when uploading
const apiResponse: any = {};
const apiResponse: any = {
success: true,
from: "Stream<>",
to: origUssname
};

// Return Etag in apiResponse, if requested
if (options.returnEtag) {
Expand Down
Loading