Skip to content

Commit

Permalink
Unit-Tests Modified
Browse files Browse the repository at this point in the history
Signed-off-by: Likhitha Nimma <[email protected]>
  • Loading branch information
likhithanimma1 committed Dec 18, 2023
1 parent 94a2339 commit 925fc8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("UnixCommand Actions Unit Testing", () => {
const mockLoadNamedProfile = jest.fn();
const mockdefaultProfile = jest.fn();
const getConfiguration = jest.fn();
const getProfileInfomock = jest.fn();

const session = new imperative.Session({
user: "fake",
Expand Down Expand Up @@ -165,6 +166,20 @@ describe("UnixCommand Actions Unit Testing", () => {
return { privateKey: undefined, keyPassphrase: undefined, handshakeTimeout: undefined };
});

getProfileInfomock.mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any);

it("test the issueUnixCommand function", async () => {
Object.defineProperty(profileLoader.Profiles, "getInstance", {
value: jest.fn(() => {
Expand All @@ -179,19 +194,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -245,19 +248,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -310,19 +301,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -368,19 +347,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -423,19 +390,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand All @@ -462,19 +417,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand All @@ -500,19 +443,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -556,19 +487,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
validProfile: ValidProfileEnum.VALID,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -625,19 +544,7 @@ describe("UnixCommand Actions Unit Testing", () => {
}),
validProfile: ValidProfileEnum.INVALID,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down Expand Up @@ -706,19 +613,7 @@ describe("UnixCommand Actions Unit Testing", () => {
checkCurrentProfile: jest.fn(),
zosmfProfile: mockLoadNamedProfile,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: false },
{ argName: "password", argValue: "TEST", secure: false },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any),
getProfileInfo: getProfileInfomock
};
}),
});
Expand Down
8 changes: 4 additions & 4 deletions packages/zowe-explorer/src/command/UnixCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class UnixCommandHandler extends ZoweCommandProvider {
let res: boolean = true;
if (!session) {
const allProfiles = profiles.allProfiles;
res = this.checkforsshrequired(allProfiles);
res = this.checkForSshRequired(allProfiles);
const profileNamesList = ProfileManagement.getRegisteredProfileNameList(globals.Trees.USS);
if (profileNamesList.length) {
if (!res) {
Expand Down Expand Up @@ -183,7 +183,7 @@ export class UnixCommandHandler extends ZoweCommandProvider {
}
}

public checkforsshrequired(allProfiles: imperative.IProfileLoaded[]): boolean {
public checkForSshRequired(allProfiles: imperative.IProfileLoaded[]): boolean {
try {
allProfiles.forEach((p) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand All @@ -198,7 +198,7 @@ export class UnixCommandHandler extends ZoweCommandProvider {

public async setsshSession(): Promise<SshSession> {
ZoweLogger.trace("UnixCommandHandler.setsshSession called.");
const sshprofile: imperative.IProfileLoaded = await this.getsshProfile();
const sshprofile: imperative.IProfileLoaded = await this.getSshProfile();
if (sshprofile) {
const cmdArgs: imperative.ICommandArguments = this.getCmdArgs(sshprofile?.profile as imperative.IProfileLoaded);
// create the ssh session
Expand Down Expand Up @@ -236,7 +236,7 @@ export class UnixCommandHandler extends ZoweCommandProvider {
return sshProfile;
}

private async getsshProfile(): Promise<imperative.IProfileLoaded> {
private async getSshProfile(): Promise<imperative.IProfileLoaded> {
ZoweLogger.trace("UnixCommandHandler.getsshParams called.");
const profileInfo = await Profiles.getInstance().getProfileInfo();
const params = ["port", "host", "user", "password"];
Expand Down

0 comments on commit 925fc8b

Please sign in to comment.