Skip to content

Commit

Permalink
added buffer and stream inspect
Browse files Browse the repository at this point in the history
Signed-off-by: jace-roell <[email protected]>
  • Loading branch information
jace-roell committed Dec 16, 2024
1 parent 664e2f3 commit ac0338e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { IUploadOptions } from "../../../../src/methods/upload/doc/IUploadOption
import { Upload } from "../../../../src/methods/upload/Upload";
import { List } from "../../../../src/methods/list/List";
import { Utilities } from "../../../../src/methods/utilities/Utilities";

import { inspect } from "util";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused import inspect.
import { ZosFilesUtils } from "../../../../src/utils/ZosFilesUtils";
import { stripNewLines } from "../../../../../../__tests__/__src__/TestUtils";
import { Create } from "../../../../src/methods/create";
Expand Down Expand Up @@ -379,7 +379,7 @@ describe("z/OS Files - Upload", () => {
expect(error).toBeDefined();
expect(error).toBe(testError);
});
it("should return with proper response when upload buffer to a data set", async () => {
it("should return with proper response when upload buffer to a data set - buffer less than 10 chars", async () => {
const buffer: Buffer = Buffer.from("testing");
const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_DS_FILES, dsName);
const reqHeaders = [ZosmfHeaders.X_IBM_TEXT, ZosmfHeaders.ACCEPT_ENCODING];
Expand All @@ -392,7 +392,27 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(response).toBeDefined();
expect(response.apiResponse).toMatchObject({"from": "Buffer<>", "success": true, "to": dsName});
expect(response.apiResponse).toMatchObject({"from": "<Buffer 74 65 73 74 69 6e 67>", "success": true, "to": dsName});

expect(zosmfPutFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfPutFullSpy).toHaveBeenCalledWith(dummySession, {resource: endpoint,
reqHeaders,
writeData: buffer});
});
it("should return with proper response when upload buffer to a data set - buffer more than 10 chars", async () => {
const buffer: Buffer = Buffer.from("bufferLargerThan10Chars");
const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_DS_FILES, dsName);
const reqHeaders = [ZosmfHeaders.X_IBM_TEXT, ZosmfHeaders.ACCEPT_ENCODING];

try {
response = await Upload.bufferToDataSet(dummySession, buffer, dsName);
} catch (err) {
error = err;
}

expect(error).toBeUndefined();
expect(response).toBeDefined();
expect(response.apiResponse).toMatchObject({"from": "<Buffer 62 75 66 66 65 72 4c 61 72 67...>", "success": true, "to": dsName});

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

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

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

expect(error).toBeUndefined();
expect(USSresponse).toBeDefined();
expect(USSresponse.apiResponse).toMatchObject({"from": "Buffer<>", "success": true, "to": dsName});
expect(USSresponse.apiResponse).toMatchObject({"from": "<Buffer 74 65 73 74 69 6e 67 0a 74 65...>", "success": true, "to": dsName});

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

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

expect(zosmfExpectFullSpy).toHaveBeenCalledTimes(1);
Expand Down
15 changes: 8 additions & 7 deletions packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Utilities, Tag } from "../utilities";
import { Readable } from "stream";
import { CLIENT_PROPERTY } from "../../doc/types/ZosmfRestClientProperties";
import { TransferMode } from "../../utils/ZosFilesAttributes";

import { inspect } from "util";

export class Upload {

Expand Down Expand Up @@ -183,10 +183,11 @@ export class Upload {
}
const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions);

const maxBufferPreviewSize = 10;
// By default, apiResponse is empty when uploading
const apiResponse: any = {
success: true,
from: "Buffer<>",
from: fileBuffer.length > maxBufferPreviewSize ? inspect(fileBuffer.subarray(0, maxBufferPreviewSize)).slice(0, -1) + "...>" : inspect(fileBuffer),
to: dataSetName
};

Expand Down Expand Up @@ -248,7 +249,7 @@ export class Upload {
// By default, apiResponse is empty when uploading
const apiResponse: any = {
success: true,
from: "Stream<>",
from: inspect(fileStream, { showHidden: false, depth: -1}),
to: dataSetName
};

Expand Down Expand Up @@ -488,11 +489,11 @@ export class Upload {
}
const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions);

const maxBufferPreviewSize = 10;
// By default, apiResponse is empty when uploading
const apiResponse: any =
{
const apiResponse: any = {
success: true,
from: "Buffer<>",
from: fileBuffer.length > maxBufferPreviewSize ? inspect(fileBuffer.subarray(0, maxBufferPreviewSize)).slice(0, -1) + "...>" : inspect(fileBuffer),
to: origUssname
};

Expand Down Expand Up @@ -556,7 +557,7 @@ export class Upload {
// By default, apiResponse is empty when uploading
const apiResponse: any = {
success: true,
from: "Stream<>",
from: inspect(uploadStream, { showHidden: false, depth: -1}),
to: origUssname
};

Expand Down

0 comments on commit ac0338e

Please sign in to comment.