This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#21 - Add new test for the InvalidCredentialManager
Signed-off-by: Wright, Christopher R <Christopher.Wright@ca.com>
- Loading branch information
Wright, Christopher R
authored and
Wright, Christopher R
committed
Sep 19, 2018
1 parent
9e08e2c
commit a2dd36a
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/security/__tests__/InvalidCredentialManager.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the * | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at * | ||
* https://www.eclipse.org/legal/epl-v20.html * | ||
* * | ||
* SPDX-License-Identifier: EPL-2.0 * | ||
* * | ||
* Copyright Contributors to the Zowe Project. * | ||
* * | ||
*/ | ||
|
||
import { InvalidCredentialManager } from "../src/InvalidCredentialManager"; | ||
import { BadCredentialManagerError } from ".."; | ||
|
||
describe("InvalidCredentialMangager", () => { | ||
it("should throw an error for every available method on the class", async () => { | ||
const error = new Error("This is a test"); | ||
const invalidManager = new InvalidCredentialManager("cli", error); | ||
const ignoreMethods = [ "constructor" ]; | ||
|
||
// Loops through the InvalidCredentialManager class's direct methods and will | ||
// check that each one throws the expected BadCredentialManagerError object. | ||
// If more methods are ever added to the invalid manager, they will be checked | ||
// to see that they do throw errors. | ||
for (const method of Object.getOwnPropertyNames(Object.getPrototypeOf(invalidManager))) { | ||
// We will ignore any methods specified in the ignoreMethods array and | ||
// only look at functions of the class. | ||
if (ignoreMethods.indexOf(method) === -1 && typeof (invalidManager as any)[method] === "function") { | ||
let caughtError: Error; | ||
|
||
try { | ||
// Try to invoke the method. We don't care about the parameters because neither should | ||
// the class throwing errors. | ||
await (invalidManager as any)[method](); | ||
} catch (e) { | ||
caughtError = e; | ||
} | ||
|
||
// Check to see if this method fails the test. | ||
if (caughtError == null || !(caughtError instanceof BadCredentialManagerError)) { | ||
fail(`InvalidCredentialManager.${method} does not properly throw a valid BadCredentialError.`); | ||
} else if (caughtError.causeErrors !== error) { | ||
fail(`InvalidCredentialManager.${method} does not preserve the error set in the constructor.`); | ||
} | ||
} | ||
} | ||
}); | ||
}); |