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 tagging for upload.bufferToUssFile #2378

Merged
merged 11 commits into from
Dec 10, 2024
4 changes: 4 additions & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe z/OS files SDK package will be documented in this file.

## Recent Changes

- BugFix: Corrected `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378)
jace-roell marked this conversation as resolved.
Show resolved Hide resolved

## `8.9.0`

- Enhancement: Added a `List.membersMatchingPattern` method to download all members that match a specific pattern.[#2359](https://github.com/zowe/zowe-cli/pull/2359)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,19 +755,22 @@ describe("Upload USS file", () => {
let error;
let uploadResponse;
let getResponse;
let tagResponse;

const data: Buffer = Buffer.from(testdata);

try {
uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true });
getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true});
tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname);
} catch (err) {
error = err;
Imperative.console.info("Error: " + inspect(error));
}

expect(error).toBeFalsy();
expect(getResponse).toEqual(Buffer.from(data.toString()));

expect(tagResponse).toBe(true);
});
it("should upload a USS file from local file", async () => {
let error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,9 @@ describe("z/OS Files - Upload", () => {
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data });
});
it("should return with proper response when upload USS file in binary", async () => {
const chtagSpy = jest.spyOn(Utilities, "chtag");
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
chtagSpy.mockImplementation(async (): Promise<any> => null);

const data: Buffer = Buffer.from("testing");
const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, dsName);
const headers = [ZosmfHeaders.OCTET_STREAM, ZosmfHeaders.X_IBM_BINARY, ZosmfHeaders.ACCEPT_ENCODING];
Expand All @@ -1673,7 +1676,7 @@ describe("z/OS Files - Upload", () => {

expect(error).toBeUndefined();
expect(USSresponse).toBeDefined();

expect(chtagSpy).toHaveBeenCalled();
expect(zosmfExpectSpy).toHaveBeenCalledTimes(1);
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data });
});
Expand Down
9 changes: 7 additions & 2 deletions packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
ImperativeExpect.toNotBeEqual(options.record, true, ZosFilesMessages.unsupportedDataType.message);
options.binary = options.binary ? options.binary : false;
ImperativeExpect.toNotBeNullOrUndefined(ussname, ZosFilesMessages.missingUSSFileName.message);
const origUssname = ussname;
ussname = ZosFilesUtils.sanitizeUssPathForRestCall(ussname);

const endpoint = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + "/" + ussname;
Expand Down Expand Up @@ -487,6 +488,12 @@
apiResponse.etag = uploadRequest.response.headers.etag;
}

if (options.encoding != null) {
await Utilities.chtag(session, origUssname, Tag.TEXT, options.encoding);

Check warning on line 492 in packages/zosfiles/src/methods/upload/Upload.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/upload/Upload.ts#L492

Added line #L492 was not covered by tests
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
} else if (options.binary) {
await Utilities.chtag(session, origUssname, Tag.BINARY);
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved
}

return {
success: true,
commandResponse: ZosFilesMessages.dataSetUploadedSuccessfully.message,
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -890,7 +897,6 @@
*/
private static get log(): Logger {
return Logger.getAppLogger();
// return Logger.getConsoleLogger();
}


Expand All @@ -915,7 +921,6 @@
const response: IUploadDir[] = [];
if (Upload.hasDirs(dirPath)) {
const directories = fs.readdirSync(dirPath).filter((file) => IO.isDir(path.normalize(path.join(dirPath, file))));
// directories = directories.filter((file) => IO.isDir(path.normalize(path.join(dirPath, file))));
for (let index = 0; index < directories.length; index++) {
const dirFullPath = path.normalize(path.join(dirPath, directories[index]));
response.push({
Expand Down
Loading