mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add test for cygwin flow
This commit is contained in:
parent
0a6fd4cbb7
commit
6826728481
1 changed files with 49 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ import { knownAikidoTools } from "../helpers.js";
|
|||
describe("Bash shell integration", () => {
|
||||
let mockStartupFile;
|
||||
let bash;
|
||||
let windowsCygwinPath = "";
|
||||
let platform = "linux";
|
||||
|
||||
beforeEach(async () => {
|
||||
// Create temporary startup file for testing
|
||||
|
|
@ -37,6 +39,35 @@ describe("Bash shell integration", () => {
|
|||
mock.module("child_process", {
|
||||
namedExports: {
|
||||
execSync: () => mockStartupFile,
|
||||
spawnSync: (command, args) => {
|
||||
if (platform !== "win32") {
|
||||
return { status: 0 };
|
||||
}
|
||||
|
||||
if (command === "where" && args[0] === "cygpath") {
|
||||
return {
|
||||
status: 0,
|
||||
stdout: Buffer.from("C:\\cygwin64\\bin\\cygpath.exe\n"),
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
command === "cygpath" &&
|
||||
args[0] === "-w" &&
|
||||
args[1] === mockStartupFile
|
||||
) {
|
||||
return {
|
||||
status: 0,
|
||||
stdout: windowsCygwinPath + "\n",
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
mock.module("os", {
|
||||
namedExports: {
|
||||
platform: () => platform,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -52,6 +83,7 @@ describe("Bash shell integration", () => {
|
|||
|
||||
// Reset mocks
|
||||
mock.reset();
|
||||
platform = "linux";
|
||||
});
|
||||
|
||||
describe("isInstalled", () => {
|
||||
|
|
@ -77,6 +109,23 @@ describe("Bash shell integration", () => {
|
|||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should use the correct startup file for cygwin bash on Windows", () => {
|
||||
platform = "win32";
|
||||
// set windows path to the correct filename
|
||||
windowsCygwinPath = mockStartupFile;
|
||||
mockStartupFile = "DUMMY"; // This will be overridden by the mocked execSync
|
||||
|
||||
const result = bash.setup();
|
||||
assert.strictEqual(result, true);
|
||||
|
||||
const content = fs.readFileSync(windowsCygwinPath, "utf-8");
|
||||
assert.ok(
|
||||
content.includes(
|
||||
"source ~/.safe-chain/scripts/init-posix.sh # Safe-chain bash initialization script"
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("teardown", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue