Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolLib.downloadTool is not answerable mocked but toolLib.extractZip requires mocks #230

Open
untra opened this issue Feb 20, 2024 · 1 comment

Comments

@untra
Copy link

untra commented Feb 20, 2024

Environment

azure-pipelines-task-lib version: 4.9.0

Issue Description

We are trying to write tests with the TaskMockRunner. For the most part we don't need any commands mocked.
Our extension in tests using toolLib.downloadTool to download a zip file, and then toolLib.extractZip to extract to a designated directory.

Under the covers the unzip task calls exec, which when used with the TaskMockRunner expects it to be mocked with an answer.
We could do this normally for other commands, however toolLib.downloadTool downloads to a temp directory with a dynamic name, that cannot be staticly defined at test time:

let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

let mock: ma.MockAnswers = new ma.MockAnswers();
// not gonna fly, path is dynamic
const answers = {
    "exec": {
        "/usr/bin/unzip .test/tmp/6bb7bc61-bf6c-4187-9cdd-8ddfd34d58a4": {
            "code": 0,
            "stdout": "mock unzip stdout here",
            "stderr": "mock unzip stderr here"
        }
    }
}
mock.initialize(answers)
tmr.setAnswers(answers)
tmr.run();

Under the covers unzip calls exec which expects to be mocked in test.

Expected behaviour

toolLib.extractZip can be used with TaskMockRunner without needing to specify a mock answer for the exec it makes.

Actual behaviour

tests that run from the TaskMockRunner cannot call toolLib.extractZip without providing exact mock answers.

Steps to reproduce

Logs

@DenisNikulin5
Copy link

Hi @untra. Thank you for your question!

Dynamic name is a default behavior. You can specify the desired file path for your file:

fileName = fileName || uuidV4();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants