Skip to content

Commit

Permalink
Change to test uploadDataset from UT
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Liang <[email protected]>
  • Loading branch information
std4lqi committed Feb 2, 2024
1 parent c83c7b2 commit c2b12d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,6 @@ describe("upload file to data set command", () => {
await connection.deleteDataset(destination); // delete the temporary member
});

it("should be able to upload a file with // to a data set and verify that the data set exists and contains the right content", async () => {
// This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533
// FTP client checks whether the string to put is a local file path first.
// If yes, it puts the whole file; otherwise, it puts the string as the contents.
// On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//".
const fileToUpload = __dirname + "/resources/file2.txt";
const memberSuffixLength = 6;
const destination = testDataSet + "(R" + generateRandomAlphaNumericString(memberSuffixLength) + ")";
const result = runCliScript(__dirname + "/__scripts__/command_upload_file_to_data_set.sh", testEnvironment,
[fileToUpload, destination]);
expect(result.stderr.toString()).toEqual("");
expect(result.status).toEqual(0);
const uploadedContent = (await connection.getDataset(destination)).toString();
const expectedContent = IO.readFileSync(fileToUpload).toString();
const uploadedLines = uploadedContent.split(/\r?\n/g);
const expectedLines = expectedContent.split(/\r?\n/g);
for (let x = 0; x < expectedLines.length; x++) {
expect(uploadedLines[x].trim()).toEqual(expectedLines[x].trim());
}
await connection.deleteDataset(destination); // delete the temporary member
});

it("should be able to upload a file to a data set in binary mode and verify that the content is correct", async () => {
const fileToUpload = testEnvironment.workingDir + "/binary.bin";
const randomContentLength = 60;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils";
import UploadStdinToDataSetHandler from "../../../../../src/cli/upload/stdin-to-data-set/StdinToDataSet.Handler";
import TestUtils from "../../TestUtils";

describe("Upload file to data set handler", () => {
describe("Upload stdio to data set handler", () => {

it("should return no data set if the data set is not found.", async () => {
const handler = new UploadStdinToDataSetHandler();
Expand All @@ -37,4 +37,31 @@ describe("Upload file to data set handler", () => {
expect(mockResponse.console.log.mock.calls[0][2]).toBe("DS1");
});

it("should upload contents with Buffer.", async () => {
// This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533
// FTP client checks whether the string to put is a local file path first.
// If yes, it puts the whole file; otherwise, it puts the string as the contents.
// On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//".

const handler = new UploadStdinToDataSetHandler();

CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss")));
CoreUtils.addCarriageReturns = jest.fn().mockReturnValue(("sss"));
const mockResponse = TestUtils.getMockResponse();
const mockUploadDataset = jest.fn();
const mockParams: any = {
arguments: {
dataSet: "ds1"
},
connection: {
uploadDataset: mockUploadDataset
},
response: mockResponse
};
await handler.processFTP(mockParams);
// The contents to upload must be Buffer. FTP client tries to fs.stat() first,
// if the contents is string.
expect(mockUploadDataset.mock.calls[0][0] instanceof Buffer).toBeTruthy();
});

});

0 comments on commit c2b12d9

Please sign in to comment.