LogicAppUnit / TestingFramework

Unit testing framework for Azure Logic Apps (Standard)
MIT License
23 stars 11 forks source link

Changed Windows used Path to Process for func.exe #20

Closed AlexanderDobrescu closed 1 year ago

AlexanderDobrescu commented 1 year ago

While implementing this framework into Azure DevOps pipelines using a self-hosted Windows and Microsoft hosted Windows build agent, the "The enviroment variable PATH does not include the path for the 'func' executable." Exception was encountered. This was found to be due to line 223 of the WorkflowTestHost.cs file.

When pipeline tasks are run which prepend tools to Path (NodeTool, FuncToolsInstaller etc.), it appears the Process path is used resulting in the exception above when the check is against the machine Path in the code.

This change does not appear to impact local testing however rectifies issues with Azure DevOps pipelines.

mark-abrams commented 1 year ago

Hi @AlexanderDobrescu , I'm having trouble re-creating your issue. How are you installing the Functions Core tools in your Azure DevOps pipeline?

AlexanderDobrescu commented 1 year ago

Hi @mark-abrams, I have tried two methods with the same result. Via npm:

- task: Npm@1
  displayName: 'Install Azure Functions core tools'
  inputs:
    command: 'custom'
    customCommand: 'install -g azure-functions-core-tools@4 --unsafe-perm true'

via FuncToolsInstaller task (also specifying other versions):

  - task: FuncToolsInstaller@0
    displayName: 'Install Functions Core Tools'
    inputs:
      version: 'latest'

During testing I created an executable which printed the Process, User, and Machine paths during the pipeline run. On both Microsoft hosted, and self-hosted Windows build agents, the tasks above were prepending the functools directory to the Process path.

When testing a linux build agent, the exception was not encountered. This would be because only one PATH exists in the OS.

Not sure if project/org settings in Azure DevOps are relevant but I've also provided them below: Project Disable anonymous access to badges - On Limit variables that can be set at queue time - On Limit job authorization scope to current project for non-release pipelines - Off Limit job authorization scope to current project for release pipelines - On Publish metadata from pipelines (preview) - Off Protect access to repositories in YAML pipelines - On Disable creation of classic build and classic release pipelines - Off

Organization Disable anonymous access to badges - On Limit variables that can be set at queue time - On Limit job authorization scope to current project for non-release pipelines - Off Limit job authorization scope to current project for release pipelines - On Protect access to repositories in YAML pipelines - On Disable stage chooser - Off Disable creation of classic build and classic release pipelines - Off

mark-abrams commented 1 year ago

Hi @AlexanderDobrescu, thanks for the information.

I've created an Azure DevOps pipeline and have re-created the issue you have identified, when installing the Azure Functions Core tools using the FuncToolsInstaller@0 action. I've also been able to re-create the issue when using the Npm@1 action - but this action doesn't seem to add the path to the func executable to the machine, user or process PATH environment variables. I'm not sure why.

I'll be releasing version 1.7.0 of LogicAppUnit in a few weeks' time so I'll approve this PR at the same time.

mark-abrams commented 12 months ago

HI @AlexanderDobrescu , I have uploaded LogicAppUnit v1.7.0 to Nuget. The new version combines the PATH environment variables for the Machine, Process and User scopes to locate the Functions runtime executable. This is an extension of the solution that you provided in this PR.