Skip to content

Commit

Permalink
added Command Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dominusmars committed Feb 29, 2024
1 parent b7dbdf7 commit 16d8fcf
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ssh.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOutput, runCommand, runCommandNoExpect, runCommandNotExpect } from "../src/modules/util/run_command";
import { changePasswordOf } from "../src/modules/password/change_passwords";
import { detect_hostname, detect_os, ejectSSHkey, makeConnection, removeSSHkey, testPassword } from "../src/modules/util/ssh_utils";
import { computers } from "./computers";
Expand All @@ -8,6 +9,7 @@ dotenv.config();
const defaultPassword = process.env.DEFAULT;

for (let computer of computers) {
console.log("\n\n\n");
describe(`SSH ${computer["OS Type"]} ${computer.Name} ${computer.ipaddress}`, () => {
let user = computer.users[0];
if (!user) {
Expand Down Expand Up @@ -80,6 +82,34 @@ for (let computer of computers) {
}
});
});
describe("Command Utils", async () => {
let ssh = await makeConnection(user, 3000, 3);
if (!ssh) {
throw new Error("Unable to connect to target server");
}

it("runCommandNotExpect", async () => {
let result = await runCommandNotExpect(ssh, "hostname", "error");

Check failure on line 92 in tests/ssh.spec.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Argument of type 'boolean | SSH2CONN' is not assignable to parameter of type 'SSH2CONN'.
assert.ok(!(typeof result === "string"), "Got Error: " + result.toString());
});
it("runCommand", async () => {
let result = await runCommand(ssh, "echo hello", "hello");

Check failure on line 96 in tests/ssh.spec.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Argument of type 'boolean | SSH2CONN' is not assignable to parameter of type 'SSH2CONN'.
if (typeof result === "string") {
assert.ok(false, result);
return;
}
assert.ok(result, "Command returned false");
});
it("runCommandNoExpect", async () => {
let result = await runCommandNoExpect(ssh, "exit 1");

Check failure on line 104 in tests/ssh.spec.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Argument of type 'boolean | SSH2CONN' is not assignable to parameter of type 'SSH2CONN'.
assert.ok(result, "Got output on expect no output");
});
it("getOutput", async () => {
let result = await getOutput(ssh, "echo This Should be Echoed");

Check failure on line 108 in tests/ssh.spec.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Argument of type 'boolean | SSH2CONN' is not assignable to parameter of type 'SSH2CONN'.
assert.ok(result.includes("This Should be Echoed"), "Got Error: " + result);
});
await ssh.close();
});

describe("SSH Key", () => {
it("Can deploy to Server", async () => {
Expand Down

0 comments on commit 16d8fcf

Please sign in to comment.