This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* directly execute the app if absolute path of the executable is provided * add tests for withInterpreter function * remove unused imports and variables * simplify the value extraction from object
- Loading branch information
1 parent
eb5f31f
commit f0f8e8d
Showing
2 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
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
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,76 @@ | ||
import { expect } from "chai"; | ||
import { withInterpreter } from "../../src/utils/misc"; | ||
|
||
describe("withInterpreter", () => { | ||
const tests = [ | ||
{ | ||
scenario: "when activation script is provided", | ||
executable: "ansible-lint", | ||
args: "playbook.yml", | ||
interpreterPath: "", | ||
activationScript: "/path/to/venv/bin/activate", | ||
expectedCommand: | ||
"bash -c 'source /path/to/venv/bin/activate && ansible-lint playbook.yml'", | ||
expectedEnv: undefined, | ||
}, | ||
{ | ||
scenario: "when no activation script is provided", | ||
executable: "ansible-lint", | ||
args: "playbook.yml", | ||
interpreterPath: "", | ||
activationScript: "", | ||
expectedCommand: "ansible-lint playbook.yml", | ||
}, | ||
{ | ||
scenario: "when absolute path of executable is provided", | ||
executable: "/absolute/path/to/ansible-lint", | ||
args: "playbook.yml", | ||
interpreterPath: "", | ||
activationScript: "", | ||
expectedCommand: "/absolute/path/to/ansible-lint playbook.yml", | ||
}, | ||
{ | ||
scenario: "when absolute path of interpreter is provided", | ||
executable: "/absolute/path/to/ansible-lint", | ||
args: "playbook.yml", | ||
interpreterPath: "/path/to/venv/bin/python", | ||
activationScript: "", | ||
expectedCommand: "/absolute/path/to/ansible-lint playbook.yml", | ||
expectedEnv: { | ||
VIRTUAL_ENV: "/path/to/venv", | ||
PATH: "/path/to/venv/bin", | ||
}, | ||
}, | ||
]; | ||
|
||
tests.forEach( | ||
({ | ||
scenario, | ||
executable, | ||
args, | ||
interpreterPath, | ||
activationScript, | ||
expectedCommand, | ||
expectedEnv, | ||
}) => { | ||
it(`should provide command ${scenario}`, () => { | ||
const actualCommand = withInterpreter( | ||
executable, | ||
args, | ||
interpreterPath, | ||
activationScript, | ||
); | ||
expect(actualCommand[0]).to.equal(expectedCommand); | ||
|
||
if (expectedEnv) { | ||
const expectedKeys = Object.keys(expectedEnv); | ||
|
||
expectedKeys.forEach((key) => { | ||
expect(actualCommand[1]).to.haveOwnProperty(key); | ||
expect(actualCommand[1][key]).to.include(expectedEnv[key]); | ||
}); | ||
} | ||
}); | ||
}, | ||
); | ||
}); |